English 中文(简体)
Can ASP.NET MVC生成的元素,名称和属性较低
原标题:Can ASP.NET MVC generate elements with lower case name and id attributes

我对协会表示仇恨。 NET html 助手在与POCO特性相同的情况下生成姓名和背后特性。

多数发展者通常使用较低的案例价值来进行姓名和补贴,但我似乎无法找到在伙伴关系中做到这一点的途径。 NET MVC。

来文方的考察表明,没有任何办法推翻这一功能,但我可能错。

这是完全可能的吗?

EDIT: I ll be more specific, with examples of what I am talking about since there seems to be some confusion.

我的模式是这样:

public class Customer
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

在我看来,我使用Html的猎物一样:

@Html.InputFor(m => m.FirstName)

这产生了这样的标志:

<input type="text" name="FirstName" id="FirstName" value="" />

我对第一民族财产被资本化表示仇恨。 在一个完美的世界里,我想用一种方式来推翻这一名词的产生,这样我就可以说“第一Name”。

我不想将POCO的财产名称改为较低。 如此之多的协会。 NET MVC框架是可加利用的,可以定制——这不是什么?

最佳回答

<代码>Display(Name = “abc”> 称Html的产出有改动。 LabelFor and when we use EditorForModel and showForModel. 它不会影响Html。 案文BoxFor的提供并不是为了改变形式田的贴现方式或名称特征。 如果你真的需要,你必须写上你本人的html助手。

public static MvcHtmlString LowerTextBoxFor<TModel,TProperty>(this HtmlHelper<TModel> html, Expression<Func<TModel,TProperty>> expr)
        {
            StringBuilder result = new StringBuilder();
            TagBuilder tag = new TagBuilder("input");
            tag.MergeAttribute("type","text");
            var lowerPropertyName = ExpressionHelper.GetExpressionText(expr).ToLower();
            tag.MergeAttribute("name",lowerPropertyName);
            tag.MergeAttribute("id",lowerPropertyName);
            result.Append(tag.ToString());
            return new MvcHtmlString(result.ToString());
        }

你们可以像现在这样利用这个“html”助手。

@Html.LowerTextBoxFor(x=>x.Property1)

了解这一例子只是产生一种id和名状。 你们将不得不对其他特性进行编码,如不侵犯性的属性,甚至对这种方法的其他超载加以有效利用。

问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签