editorfor

DataType attribute wrecking jQuery datepicker on Datetime field

那年仲夏 提交于 2020-03-01 07:24:19
问题 I am using MVC 4 and Razor views and am having trouble understanding why the Edit view on my Date field is not binding properly to the built in jQuery datepicker. The field is of datatype Date in the Database, and DateTime in the domain model. I do not wish to show time, only the date. The field is required and needs formatting. My view looks like this : <div class="editor-label"> @Html.LabelFor(model => model.Appointment.EndDate) </div> <div class="editor-field"> @Html.EditorFor(model =>

Input with date format set from ViewModel and html class attribute

淺唱寂寞╮ 提交于 2020-01-24 04:52:10
问题 I am working with razor view engine in asp.net mvc3. Now, I need an input for a DateTime which should display the value in a fixed format (say dd-MMM-yyyy ). So I can do: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MMM-yyyy}")] public DateTime StartDate { get; set; } And in the view: @Html.EditorFor(model => model.StartDate) But I need to add a class in the input. Which I think is not possible in EditorFor . So I could use @Html.TextBoxFor(model => model.StartDate,

Overriding the default EditorFor template-selecting in ASP.NET MVC 3 RC

两盒软妹~` 提交于 2020-01-14 08:05:33
问题 I'm creating a MVC-application which currently uses EditorFor to gennerate a lot of views. The whole view is basically just an EditorForModel, and it works great. However, I've reached one small problem, which I can't seem to find a solution for, and it is important that it works the way I need it to, and that is when trying to render EditorFor an interface. The bindings and everything like that's been taken care of, but the problem is that the EditorFor sees that it's an interface, and

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

你离开我真会死。 提交于 2019-12-30 09:06:14
问题 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

Trying to use EditorFor with an ICollection<string> in an ASP.NET MVC3 View?

孤街醉人 提交于 2019-12-22 08:14:19
问题 I'm trying to display a class object in a Create view, where a property is an ICollection<string> . For example... namespace StackOverflow.Entities { public class Question { public int Id { get; set; } .... public ICollection<string> Tags { get; set; } } } and if the view was like a StackOverflow 'ask a question' page, where the Tags html element is a single input box .. I'm not sure how I could do that in an ASP.NET MVC3 view? Any ideas? I tried using EditorFor but nothing was displayed in

Override EditorForModel Template

ぃ、小莉子 提交于 2019-12-22 07:23:30
问题 You can provide alternate templates for individual types, but is it possible to override the template that wraps the label, field and validation up. Change: <div class="editor-label"><label for="Content">Content</label></div> <div class="editor-field"><input class="text-box single-line" id="Content" name="Content" type="text" value="" /> </div> To: <div class="field"> <label for="Content">Content</label> <input class="text-box single-line" id="Content" name="Content" type="text" value="" /> <

when passing a collection to EditorFor(), it generates invalid names for input elements

房东的猫 提交于 2019-12-20 14:19:20
问题 I have a BookCreateModel which consists of book's plane info such as Title, PublishYear & etc plus a collection of book Authors (complex type) : public class BookCreateModel { public string Title { get; set; } public int Year { get; set; } public IList<AuthorEntryModel> Authors { get; set; } } public class AuthorEntryModel { public string FirstName { get; set; } public string LastName { get; set; } } in CreateBook view I have used EditorFor helper : @Html.EditorFor(m => m.Authors,

unable to apply Bootstrap classes to my EditorFor

Deadly 提交于 2019-12-17 20:53:38
问题 I am working on an asp.net mvc-5 web application , and i wrote the following :- @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) & @Html.EditorFor(model => model.Name, new { @class = "form-control" }) but this will not have any effect on the generated html, but if i changed the EditorFor to be T extboxFor i will get the effect for the form-control class ? can anyone advice on this please ? i read that this is supported only inside asp.net mvc 5.1

Html5 Placeholders with .NET MVC 3 Razor EditorFor extension?

非 Y 不嫁゛ 提交于 2019-12-17 04:12:45
问题 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. 回答1: You may take a look at the following article for writing a custom

ASP.NET MVC UI Template: How to mix an IList Model property with EditorFor( m => m.subModel)?

心已入冬 提交于 2019-12-13 17:23:39
问题 Say you have this: public class ShoppingCart { public IList<CartItem> cartItems {get; set; } } And you do this to render the class: <%= EditorFor( m => m.ShoppingCart, "ShoppingCart") %> How would you do the EditorFor( ??, "CartItem") in the ShoppingCart.ascx? I would think it would look something like this: <% foreach( CartItem myCartItem in m.cartItems) { %><%= EditorFor( ??, "CartItem") %><% } %> The idea here of course is to use a UI template for an entire class, not just a property. 回答1: