Tag: asp.net mvc 4

MVC 4razor数据注释ReadOnly

ReadOnly属性似乎不在MVC 4中。可编辑(false)属性不能按照我希望的方式工作。 有类似的东西有效吗? 如果没有,那么我如何创建自己的ReadOnly属性,如下所示: public class aModel { [ReadOnly(true)] or just [ReadOnly] string aProperty {get; set;} } 所以我可以这样说: @Html.TextBoxFor(x=> x.aProperty) 而不是这(它确实有效): @Html.TextBoxFor(x=> x.aProperty , new { @readonly=”readonly”}) 或者这(它确实有效,但未提交值): @Html.TextBoxFor(x=> x.aProperty , new { disabled=”disabled”}) http://view.jquerymobile.com/1.3.2/dist/demos/widgets/forms/form-disabled.html 这样的事可能吗? https://stackoverflow.com/a/11702643/1339704 注意: [可编辑(假)]无效

MVC4多按钮forms不起作用JQM

我在MVC4中面对我的JQuery移动APP上的一个奇怪的问题: 我有一个表格,里面有几个这样的texbox @using Models @model Models.DataModel.Pagina_Details @{ Layout = “~/Views/Shared/_Layout.cshtml”; } @using (Html.BeginForm(“Pagina_Details”, “Home”, FormMethod.Post, new { id = “PaginaDetailsForm” })) { if (Request.QueryString[“Command”] != null) { Session[“Command”] = Request.QueryString[“Command”]; } else { Response.Redirect(“Index”); } Pagina’s @Html.HiddenFor(model => model.ID) @Html.LabelFor(model => model.Name, “Naam *”, new { @class = “lbl”}) @Html.TextBoxFor(model => model.Name, new { required […]

未找到System.ComponentModel.DataAnnotations.Schema

我遇到涉及System.ComponentModel.DataAnnotations.Schema命名空间的Visual Studio 2012中的问题。 它告诉我,ForeignKeyAttribute无法解析,过去的解决方案是添加下面注释掉的using语句。 VS2012无法像VS2010那样解析Schema名称空间。 在最近的.Net版本中是否有任何改变会导致这个问题? 如果是这样,我该如何解决它们? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; // using System.ComponentModel.DataAnnotations.Schema; namespace Data { public class AffiliateUser { [Key, ForeignKey(“User”)] public int UserId { get; set; } [StringLength(50)] public string AffiliateUserKey { get; set; } public Guid ApiKey { get; set; } public string PasswordHash { […]

ResolveBundleUrl无法解析所有文件?

我是MVC的新手,所以我想开始一个新项目并尝试MVC4中的一些新function。 我的Content目录中有两个css文件, normalise_mini和site.css 。 当我使用以下代码时: 它只需要我的site.css文件而不是我的规范化文件。 我的应用开始时有以下内容: protected void Application_Start() { // Remove all other view engines except razor: ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); BundleTable.Bundles.RegisterTemplateBundles(); BundleTable.Bundles.EnableDefaultBundles(); } 我是否需要为每个css文件创建一个包(就像这个人一样)? 或者它应该只是自动找到所有的css文件(我希望这是默认行为)。 值得注意的是,我开始将这个项目作为基于Razor视图引擎的空网站(实际上根本不是空的:/) 提前致谢 更新 根据发布的链接,我需要注释掉注册模板包的行。 例如: protected void Application_Start() { // Remove all other view engines except razor: ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); //BundleTable.Bundles.RegisterTemplateBundles(); // […]

将viewbag从动作控制器传递到局部视图

我有一个部分视图的mvc视图。控制器中有一个ActionResult方法,它将返回一个PartialView。 所以,我需要将ViewRag数据从ActionResult方法传递给Partial View。 这是我的控制器 public class PropertyController : BaseController { public ActionResult Index() { return View(); } public ActionResult Step1() { ViewBag.Hello = “Hello”; return PartialView(); } } 在Index.cshtml视图中 @Html.Partial(“Step1”) Step1.cshtml局部视图 @ViewBag.Hello 但这不起作用。 那么,从viewbag获取数据的正确方法是什么。 我想我正在遵循错误的方法。 请指导我。

忽略ASP.NET MVC中的路由

我正在学习使用ASP.NET MVC中的路由,并且我正在尝试理解IgnoreRoute方法。 我试图阻止用户访问”Content/{filename}.html” 。 我把它作为RegisterRoutes方法中的第一个调用。 这是我的代码: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“Content/{filename}.html”); routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute(“MyRoute”, “{controller}/{action}/{id}/{*catchall}”, new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }, new { controller = “^.*”, action = “^Index$|^About$” }, new[] { “UrlsAndRoutes.AditionalControllers” }); routes.MapRoute(“MyRoute2”, “{controller}/{action}/{id}/{*catchall}”, new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }, […]

记录在log4net AdoNetAppender中延迟了?

我有一个像这样的AdoNetAppender设置: 从技术上讲它是有效的,因为当我停止在IIS 8 Express上运行的网站时,记录会显示出来。 然而,这正是问题所在,直到我停止网站才会显示记录。 我试过useTransactions打开和关闭。 有人可以帮忙吗?

如何解决错误:该类型似乎没有实现microsoft.practices.servicelocation.iservicelocator?

我是MVC的新手,我正在关注Adam Freeman的 “ PRO ASP.NET MVC 4 ”。 我目前正在编写第6章。 我正在学习如何在MVC 4中使用Ninject进行dependency injection。 我按照书中的描述创建了应用程序。 现在我无法得到以下错误的原因: 该类型似乎没有实现microsoft.practices.servicelocation.iservicelocator 这是我的控制器代码: public class HomeController : Controller { private Product[] products = { new Product {Name = “Kayak”, Category = “Watersports”, Price = 275M}, new Product {Name = “Lifejacket”, Category = “Watersports”, Price = 48.95M}, new Product {Name = “Soccer ball”, […]

名称’X509Certificate2UI’在当前上下文中不存在

在Asp Net MVC4应用程序中使用X509Certificate2UI类是否有任何问题 using System.Security.Cryptography.X509Certificates; private static X509Certificate2 PickCertificate(StoreLocation location, StoreName name) { try { store.Open(OpenFlags.ReadOnly); //PROBLEM IS HERE X509Certificate2 cert = X509Certificate2UI.SelectFromCollection(store.Certificates, “Caption”, “Message”, X509SelectionFlag.SingleSelection)[0]; } catch (Exception) { throw; } } 它抱怨当前上下文中没有’X509Certificate2UI’名称不知道,因为该类在System.Security.Cryptography.X509Certificates;

如何定义路由中的PUT方法仅限于没有参数的控制器中的Put方法?

以下是WebApiConfig.cs中的路由配置: config.Routes.MapHttpRoute( name: “DefaultApiPut”, routeTemplate: “api/{controller}”, defaults: new { httpMethod = new HttpMethodConstraint(HttpMethod.Put) } ); config.Routes.MapHttpRoute( name: “DefaultApi”, routeTemplate: “api/{controller}/{id}”, defaults: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get, HttpMethod.Post, HttpMethod.Delete) } ); 这是我的控制器: public class MyController : ApiController { [HttpPut] public void Put() { //blah } } 不知何故,当客户端使用URL /api/myController/12345发出PUT请求时,它仍然映射到MyController的Put方法,我预计会出现类似资源的错误。 如何强制Put方法只接受没有参数的请求? 提前致谢!