editorfor

Why is EditorFor in my ASP.NET MVC 2 application throwing ArgumentNullException?

家住魔仙堡 提交于 2019-12-02 15:51:13
问题 I have a weird problem with EditorFor in one of my views. The following code throws an ArgumentNullException. <%: Html.EditorFor(x => x.Name) %> However, the following code is fine. <%: Html.TextBoxFor(x => x.Name) %> Model.Name is a string variable - and it's set. EditorFor works in another view - until this view crashes, at which point then I have to restart the development web server (Cassini) or all the EditorFor calls crash with the same message. I ran a test with the MVC 2 source,

Why is EditorFor in my ASP.NET MVC 2 application throwing ArgumentNullException?

那年仲夏 提交于 2019-12-02 09:55:07
I have a weird problem with EditorFor in one of my views. The following code throws an ArgumentNullException. <%: Html.EditorFor(x => x.Name) %> However, the following code is fine. <%: Html.TextBoxFor(x => x.Name) %> Model.Name is a string variable - and it's set. EditorFor works in another view - until this view crashes, at which point then I have to restart the development web server (Cassini) or all the EditorFor calls crash with the same message. I ran a test with the MVC 2 source, hoping I could get some insight, but that worked OK! Presumably the MVC 2 RTM source on there should be the

How to customize the EditorFor CSS with razor

假装没事ソ 提交于 2019-12-02 00:58:42
问题 I have this class public class Contact { public int Id { get; set; } public string ContaSurname { get; set; } public string ContaFirstname { get; set; } // and other properties... } And I want to create a form that allo me to edit all those fields. So I used this code <h2>Contact Record</h2> @Html.EditorFor(c => Model.Contact) This works fine, but I want to customize how the elements are displayed. For instance I want each field to be displayed in the same line as its label. Because now, the

How to customize the EditorFor CSS with razor

泄露秘密 提交于 2019-12-01 20:35:17
I have this class public class Contact { public int Id { get; set; } public string ContaSurname { get; set; } public string ContaFirstname { get; set; } // and other properties... } And I want to create a form that allo me to edit all those fields. So I used this code <h2>Contact Record</h2> @Html.EditorFor(c => Model.Contact) This works fine, but I want to customize how the elements are displayed. For instance I want each field to be displayed in the same line as its label. Because now, the generated html is like this : <div class="editor-label"> <label for="Contact_ContaId">ContaId</label> <

Forcing EditorFor to prefix input items on view with Class Name?

烈酒焚心 提交于 2019-12-01 05:59:22
I have an EditorFor: <%: Html.EditorFor(model => model.Client, "ClientTemplate", new { editing = false })%> This will bind coming down to the view fine (as expected) but will not bind bind back when the model gets posted. This is due to the form id's not being prefixed with "Client." Usually in this situation i just pass in model and then bind the inputs to model.Client.PropertyName in the Template but this is not an option in this case as the template is used on two different viewmodels (that have client on). Any suggestions on getting this to bind properly? Many thanks, Kohan. Addendum It

Hide editor-label for public property when calling EditorFor(…)?

落爺英雄遲暮 提交于 2019-12-01 04:48:42
When calling Html.EditorFor(m => m) , where m is a public class with public properties, a hidden input and a label are displayed for properties with the [HiddenInput] attribute. How can I hide the label without making it private or creating an editor template? Example public class User { [HiddenInput] public Guid ID { get; set; } // should not be displayed in editor template public string Name { get; set; } // should be editable } Undesired result for ID property by EditorFor(...) with label <div class="editor-label"> <label for="ID">ID</label> <!-- Why is this here? --> </div> <div class=

Forcing EditorFor to prefix input items on view with Class Name?

♀尐吖头ヾ 提交于 2019-12-01 03:13:45
问题 I have an EditorFor: <%: Html.EditorFor(model => model.Client, "ClientTemplate", new { editing = false })%> This will bind coming down to the view fine (as expected) but will not bind bind back when the model gets posted. This is due to the form id's not being prefixed with "Client." Usually in this situation i just pass in model and then bind the inputs to model.Client.PropertyName in the Template but this is not an option in this case as the template is used on two different viewmodels

jQuery DatePicker MVC4 EditorFor

跟風遠走 提交于 2019-11-30 13:23:26
I need to use datepicker on an EditorFor field. My code for the view is: <div class="editor-label"> @Html.Label("birthDate","birthDate") </div> <div class="editor-field"> @Html.EditorFor(model => model.birthDate, new { @class = "datepicker"}) @Html.ValidationMessageFor(model => model.birthDate) </div> The script: <script type="text/javascript"> $(document).ready( function () { $('.datepicker').datepicker({ changeMonth: true, changeYear: true, minDate: "-99Y", dateFormat: "dd/mm/yyyy" }); }); I can't make it work. I have the following error: Microsoft JScript runtime error: Object doesn't

EditorFor collection of items in my model

让人想犯罪 __ 提交于 2019-11-29 23:05:27
My ViewModel has a property that is a collection of another of my model entities, in this case CategoryTags (and each tag has a Tag and an ID). 1) Am I correct in understanding that Html.EditorFor() doesn't have an UI it can create for an ICollection? 2) Assuming #1, I've decided to make an EditorTemplate that is a textbox where my user can key in comma-separated tag names and jquery will autocomplete. Will I have to pass back the list of tag names (or their respective IDs) and then parse them back into the CategoryTags propety on POST? Thanks! Correct - you need your own template (See http:/

Can EditorFor() be used to create <input type=“file”>?

谁说胖子不能爱 提交于 2019-11-29 02:59:12
Given this model, is it possible to use the Html.EditorFor() to render a file upload input element to the page? I played around with the Datatype of the property FileName, and it was definitely impacting the editor form rendered. public class DR405Model { [DataType(DataType.Text)] public String TaxPayerId { get; set; } [DataType(DataType.Text)] public String ReturnYear { get; set; } public String FileName { get; set; } } Strongly Typed *.aspx page looks like this <div class="editor-field"> <%: Html.EditorFor(model => model.FileName) %> <%: Html.ValidationMessageFor(model => model.FileName) %>