editorfor

HTML.EditorFor with 3 decimal places

邮差的信 提交于 2019-12-12 10:34:37
问题 How to display the model decimal field with 3 decimal places. Currently it shortens it to 2 digits. 1,237 currently will be displayed as 1,24 ;) 回答1: You can use Data Annotations on your View Model, like this: [DisplayFormat(DataFormatString = "{0:0.00}", ApplyFormatInEditMode = true)] public decimal Num { get; set; } 来源: https://stackoverflow.com/questions/16232653/html-editorfor-with-3-decimal-places

MVC editorfor not working for collection

元气小坏坏 提交于 2019-12-11 11:44:09
问题 I have a model class called Events and a model class called EventRange: public class Event { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public List<EventRange> RangesCollection { get; set; } } public class EventRange { public int Id { get; set; } public string RangeName { get; set; } public string RangeDescription { get; set; } public int Capacitiy { get; set; } } As you can see the Event class contains a List for as many EventRanges

MVC3 collection model binding with EditorFor

我的梦境 提交于 2019-12-10 10:57:49
问题 Regarding this post and this other one. Suppose I have the following: public class Foo { public string Value1 { get; set; } public string Value2 { get; set; } } public class BarViewModel { public string Baz { get; set; } public IList<Foo> Foos { get; set; } } And I have a view that receive a BarViewModel : @model BarViewModel @Html.EditorFor(model => model.Baz) <table> @for(int i = 0 ; i < Model.Foos.Count ; i ++) { string name1 = "Foos[" + i.ToString() + "].Value1"; string name2 = "Foos[" +

ASP.NET MVC - DisplayFormat attribute

送分小仙女□ 提交于 2019-12-08 11:02:06
问题 In my model i've the MyDate property that has datetime type. I sign the property with the DisplayFormat attribute in this mode: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy hh:mm}")] public DateTime MyDate { get; set; } in my view: ... <%= Html.EditorFor(model => model.Evento.MyDate)%> ... why if the value of property is '2011-05-03 14:47', in my view (into EditorFor) i see '03/05/2011 02.47' ? The DataFormatString is correct! thanks so much for reply Alberto

ASP.Net MVC 2.0: EditorFor setting name via attributes

三世轮回 提交于 2019-12-07 22:58:35
问题 Just wondering how do I mimic the following using attributes... <%= Html.EditorFor(x => x.SportProgramIdList, "FormMultiSelectDropDownList", "SportProgramIds")%> I know I can specify the template by using [UIHint("FormMultiSelectDropDownList")] but I am left with the problem with how to set the name... Cheers Anthony 回答1: I Guess you'll have to create your own CustomAttribute UINameAttribute . You could use the ModelMetadata to keep your attribute and then I'm not sure what would be the best

Binding nested model with MVC3 on HttpPost

孤者浪人 提交于 2019-12-07 09:28:30
问题 I am new to MVC3. I have a submit button on a form and I want to bind a model which has 2-3 nested object models with many properties inside. Is there a way to bind these nested objects without using EditorFor; so that when I submit the form I will take on ActionResult(Object model) on model that is being returned, the nested object models with their values without having to implement hidden values or forms behind on html? 回答1: basically you need enough values to identify your model again. So

ASP.NET MVC: Accessing ViewModel Attributes on the view

时光怂恿深爱的人放手 提交于 2019-12-07 06:58:23
问题 Is there any way to access any attributes (be it data annotation attributes, validation attributes or custom attributes) on ViewModel properties from the view? One of the things I would like to add a little required indicator next to fields whose property has a [Required] attribute. For example if my ViewModel looked like this: public class MyViewModel { [Required] public int MyRequiredField { get; set; } } I would want to do something in the EditorFor template like so: <%@ Control Language=

MVC3 collection model binding with EditorFor

空扰寡人 提交于 2019-12-06 09:30:55
Regarding this post and this other one . Suppose I have the following: public class Foo { public string Value1 { get; set; } public string Value2 { get; set; } } public class BarViewModel { public string Baz { get; set; } public IList<Foo> Foos { get; set; } } And I have a view that receive a BarViewModel : @model BarViewModel @Html.EditorFor(model => model.Baz) <table> @for(int i = 0 ; i < Model.Foos.Count ; i ++) { string name1 = "Foos[" + i.ToString() + "].Value1"; string name2 = "Foos[" + i.ToString() + "].Value2"; <tr> <td> <input type="text" name="@name1" value="@Model.Foos[i].Value1" />

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

£可爱£侵袭症+ 提交于 2019-12-05 13:55:29
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 the browser, because it's not sure how to render a collection of strings. Start by decorating your view

Binding nested model with MVC3 on HttpPost

我只是一个虾纸丫 提交于 2019-12-05 13:21:59
I am new to MVC3. I have a submit button on a form and I want to bind a model which has 2-3 nested object models with many properties inside. Is there a way to bind these nested objects without using EditorFor; so that when I submit the form I will take on ActionResult(Object model) on model that is being returned, the nested object models with their values without having to implement hidden values or forms behind on html? basically you need enough values to identify your model again. So you can go with a Id in a hidden field and all the properties you want to change. To recreate your model