Tag: asp.net mvc

Visual Studio 2012 MVC构建错误:名称空间“System.Data.Entity”中不存在类型或命名空间名称“Infrastructure”

更新:在参考管理器中选择了对System.Data.Entity的程序集引用。 安装程序 尝试运行开箱即用的ASP.NET MVC 3 Web应用程序时出错。 我没有做任何修改。 我只选择了文件>新建项目> Visual C#> ASP.NET MVC 3 Web应用程序,并保留所有默认设置。 在项目设置下 ,我为模板选择了Internet Application ,为视图引擎选择了Razor ,并选中了使用HTML5语义标记 。 然后我立即选择了Build> Build Solution ,它失败并产生了这个错误和其他五个警告(如屏幕截图所示)。 错误 错误1命名空间“System.Data.Entity”中不存在类型或命名空间名称“Infrastructure”(您是否缺少程序集引用?) C:\ Users \ johndoe \ Documents \ Visual Studio 2012 \ Projects \ MvcApplication1 \ MvcApplication1 \ Global.asax.cs 是的我知道… …… 这个问题已被问过 很多次 – 但这些post的答案并没有提供足够的信息来解决我的问题。 请详细说明您的回复 ,并逐步说明,因为我是Visual Studio及其MVC应用程序开发框架的新手。 问题 什么会导致Visual […]

如何序列化原始json字段?

我在db中有一个存储json字符串的字段,当我在json结果中返回它时,我想要它将作为json原始数据返回,而不是用引号作为字符串扭曲。 更新1(更多信息):如果您查看图像字段,它包含原始的json字符串值 但是在用JsonResult序列化之后,它会被引号扭曲,因为它是一种String类型,我怎么能告诉序列化器将图像字段视为原始json数据呢? var db = new ModelsContainer(); var res = db.Images.OrderByDescending(i=>i.DateCreated).Skip(skip).Take(take).Select( i => new { id = i.Id, dateCreated = i.DateCreated, images = i.Images , user = new { id = i.User.Id, facebookId = i.User.FacebookId, displayName = i.User.DisplayName }, tags = i.Tags.Select( t => t.Value ) }).ToList(); return Json(res, JsonRequestBehavior.AllowGet); [ { “id”:”5c528e88-f3a7-4b30-9746-980867325fd1″, “dateCreated”:”\/Date(1364381593000)\/”, […]

未找到entity framework方法; 版本问题?

我正在研究另一个开发人员构建的系统。 当我运行该项目时,我在运行时收到以下错误。 这是一个entity framework方法吗? 它来自特定版本吗? 我不确定如何追查此错误的来源。 System.MissingMethodException:找不到方法:’Void System.Data.Entity.ModelConfiguration.EntityTypeConfiguration`1.ToTable(System.String)’。

通过电子邮件恢复/重置丢失的密码选项

我正在使用DefaultMembershipProvider开发一个C#ASP.MVC 4项目,我正在尝试用一种用户友好的方式来恢复/重置丢失的密码。 我的第一次尝试是让用户提供他们的用户名(这是一个有效的电子邮件地址),然后应用程序将生成随机密码(符合我们的要求),然后将密码通过电子邮件发送给用户。 我的理想解决方案是当用户点击忘记密码按钮时。 系统会询问他们的用户名,这些用户名在提供时会导致电子邮件与URL一起发送(此URL也会附加到期日期)。 此解决方案还会重置应用程序内的用户密码(在发送电子邮件之前)。 当用户点击URL时,他们会自动登录并发送到更改密码表单。 这个解决方案有问题吗? 对于配置,我设置了以下值:

谷歌日历Api在本地工作正常但不提高其在服务器上的身份validation

我在console.developers.google.com创建了一个项目以使用Google Calendar API 。 我们需要生成凭证并选择应用程序类型 对于Localhost和应用程序类型, other以下是Json工作正常。 { “installed”: { “client_id”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com”, “project_id”: “xxxxxx-00000”, “auth_uri”: “https://accounts.google.com/o/oauth2/auth”, “token_uri”: “https://accounts.google.com/o/oauth2/token”, “auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”, “client_secret”: “xxxxxxxxxxxx”, “redirect_uris”: [ “urn:ietf:wg:oauth:2.0:oob”, “http://localhost” ] } } 对于应用程序类型Web Application在服务器上托管少数参数在Json具有不同的值,如下所示。 { “web”: { “client_id”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com”, “project_id”: “xxxxxxxx-99999”, “auth_uri”: “https://accounts.google.com/o/oauth2/auth”, “token_uri”: “https://accounts.google.com/o/oauth2/token”, “auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”, “client_secret”: “xxxxxxxxxxxxxxxxxxxxxxx”, “redirect_uris”: [ “http://demo.mydemo.com” ], “javascript_origins”: [ “http://demo.mydemo.com” ] } […]

Owin Authentication.SignIn不工作

我尝试使用owin身份validation管理器来validation用户,但User.Identity.IsAuthenticated仍然是假的。 Startup.cs public partial class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } Startup.Auth.cs public partial class Startup { public static Func<UserManager> UserManagerFactory { get; set; } public Startup() { UserManagerFactory = () => { var userManager = new UserManager(new CustomUserStore()); return userManager; }; } public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { […]

ValueProvider不包含TryGetValue的定义

在我的应用程序中,我试图从日期和时间字段中分割日期和时间,以便我可以在日期上放置一个jQuery日期选择器。 我找到了Hanselman用于拆分DateTime的代码 ,但是我在bindingContext.ValueProvider.TryGetValue(modelName, out valueResult);上bindingContext.ValueProvider.TryGetValue(modelName, out valueResult);编译错误bindingContext.ValueProvider.TryGetValue(modelName, out valueResult); 。 我得到的错误是: 错误3’System.Web.Mvc.IValueProvider’不包含’TryGetValue’的定义,并且没有可以找到接受类型’System.Web.Mvc.IValueProvider’的第一个参数的扩展方法’TryGetValue’(你错过了吗? using指令或程序集引用?)C:\ Documents and Settings \ xxx \ My Documents \ Visual Studio 2008 \ Projects \ MyProject \ Project \ Helpers \ DateAndTimeModelBinder.cs 83 42项目 我错过了什么? 我创建了一个新类,并将他的代码放在我项目的Helpers文件夹中。

C#MVC.Net格式货币,不带小数

我正在寻找一个将浮动显示为货币的DataFormatString。 但如果它们不相关(0),则省略小数值。 目前我正在使用: [DisplayFormat(DataFormatString = “{0:C}”)] 在我的模特。 这正确显示为货币。 我无法找到任何详细说明我需要做出哪些更改来省略小数位的地方?

仅在从特定操作重定向时才允许访问操作

是否有一种限制对操作的访问权限的好方法,因此如果您从另一个操作重定向,则只能访问它。 例如: [HttpPost] public virtual ActionResult Create(MyViewModel vm) { if (ModelState.IsValid) { // do some work return RedirectToAction(“CreateSuccess”); } else { return View(vm); } } public virtual ActionResult CreateSuccess() { // only allow execution if you were redirected from Action “Create” }

我无法关闭ASP.NET MVC控制器的请求validation

我试图通过执行以下操作关闭控制器中所有操作方法的请求validation: [ValidateInput(false)] public class MyController : Controller { … 我正在使用的参考说这是可能的,并告诉我这样做,但由于某种原因,它不起作用。 如果我通过文本框提交任何html(甚至是简单的标签),我会收到错误消息: 从客户端检测到潜在危险的Request.Form值(text = “)。 通过将属性附加到单个方法也无法正常工作。 如何禁用控制器的请求validation? 编辑 我在VS2008内置测试服务器。