editorfor

MVC3 EditorFor readOnly

时光怂恿深爱的人放手 提交于 2019-11-26 20:06:02
问题 I want to make readOnly with EditorFor in edit page. I tried to put readonly and disabled as: <div class="editor-field"> @Html.EditorFor(model => model.userName, new { disabled = "disabled", @readonly = "readonly" }) </div> However, it does not work. How can I make to disable edit this field? Thank you. 回答1: The EditorFor html helper does not have overloads that take HTML attributes. In this case, you need to use something more specific like TextBoxFor: <div class="editor-field"> @Html

Html5 Placeholders with .NET MVC 3 Razor EditorFor extension?

依然范特西╮ 提交于 2019-11-26 18:06:53
Is there a way to write the Html5 placeholder using @Html.EditorFor, or should I just use the TextBoxFor extension i.e. @Html.TextBoxFor(model => model.Title, new { @placeholder = "Enter title here"}) Or would it make sense to write our own custom extension that can maybe use the 'Description' display attribute via DataAnnotations (similar to this )? Of course, then the same question applies to 'autofocus' as well. You may take a look at the following article for writing a custom DataAnnotationsModelMetadataProvider . And here's another, more ASP.NET MVC 3ish way to proceed involving the newly

EditorFor() for a List of Complex Type (MVC)

[亡魂溺海] 提交于 2019-11-26 16:16:54
问题 I'm trying to create an EditorFor() for a List of a Complex Type. Specifically the "Options" below should get displayed in a one multitext input where each option(string) is in a new line. However, I can only display one option in a textbox and not all options.... My View Model and Class: public class ItemViewModel { public int itemId { get; set; } [UIHint("Option")] public List<Option> Options { get; set; } } public class Option { public string Text { get; set; } } My Editor Templates:

Converting HTML.EditorFor into a drop down (html.dropdownfor?)

你离开我真会死。 提交于 2019-11-26 16:16:32
问题 Currently I am using a Html.EditorFor control in a default 'Create' View page like this. <%: Html.EditorFor(model => model.IsActive) %> I would like to convert this to a drop down with values and still be binded to the model in the view. My question is two fold. If there are only 2/3 values needed in the drop down..Is there a quick way to explicitly populate 2 or 3 values? If the list is big and needs to come from a sql query, how to do this? Thanks in advance for the help. 回答1: In order to

Html attributes for EditorFor() in ASP.NET MVC

南楼画角 提交于 2019-11-26 15:48:28
Why can't I pass in html attributes to EditorFor() ? eg; <%= Html.EditorFor(model => model.Control.PeriodType, new { disabled = "disabled", readonly = "readonly" }) %> I don't want to use metadata Update : The solution was to call this from the view : <%=Html.EditorFor( model => model.Control.PeriodEndDate, new {Modifiable=model.Control.PeriodEndDateModifiable})%> and use ViewData["Modifiable"] in my custom EditorTemplates/String.ascx where I have some view logic that determines whether to add readonly and/or disabled attributes to the input The anonymous object passed into EditorFor() is a

Html attributes for EditorFor() in ASP.NET MVC

℡╲_俬逩灬. 提交于 2019-11-26 04:38:06
问题 Why can\'t I pass in html attributes to EditorFor() ? eg; <%= Html.EditorFor(model => model.Control.PeriodType, new { disabled = \"disabled\", readonly = \"readonly\" }) %> I don\'t want to use metadata Update : The solution was to call this from the view : <%=Html.EditorFor( model => model.Control.PeriodEndDate, new {Modifiable=model.Control.PeriodEndDateModifiable})%> and use ViewData[\"Modifiable\"] in my custom EditorTemplates/String.ascx where I have some view logic that determines

MVC4 DataType.Date EditorFor won&#39;t display date value in Chrome, fine in Internet Explorer

一曲冷凌霜 提交于 2019-11-26 01:48:30
问题 I\'m using the DataType.Date attribute on my model and an EditorFor in my view. This is working fine in Internet Explorer 8 and Internet Explorer 9, but in Google Chrome it is showing a date picker and instead of displaying the value it just displays \"Month/Day/Year\" in faded gray text. Why won\'t Google Chrome display the value? Model: [DataType(DataType.Date)] public Nullable<System.DateTime> EstPurchaseDate { get; set; } View: <td class=\"fieldLabel\">Est. Pur. Date</td> <td class=\