mvc-editor-templates

Generic EditorTemplate for an Enum with Text Select Option Value

大兔子大兔子 提交于 2020-02-04 07:31:07
问题 I have been using this editor template for enums: @model Enum @{ var htmlAttributesFromView = ViewData["htmlAttributes"] ?? new { }; var htmlAttributes = Html.MergeHtmlAttributes(htmlAttributesFromView, new { @class = "form-control" }); } <div class="form-group"> @Html.LabelFor(model => model, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-8"> @Html.EnumDropDownListFor(x => x, htmlAttributes) @Html.ValidationMessageFor(model => model) </div> <a class=

DisplayFormat not getting applied on decimal value

半世苍凉 提交于 2020-01-14 07:35:09
问题 I have a model property I'm trying to render using an EditorFor template, and I'm trying to apply formatting using the DisplayFormat attribute. However, it's not working at all -- it's totally being ignored. Here is my template: @model System.Decimal? @Html.TextBoxFor(m => m) Here is my model: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0.00}")] public decimal? Retail { get; set; } Here is my view: @Html.EditorFor(m => m.Retail) But it's rendering a textbox with the

Asp.Net MVC3 Razor - child items list not posting back from editor

▼魔方 西西 提交于 2020-01-13 11:46:07
问题 I'm trying to create a multi-level editor in MVC3. By multi-level I mean that I would like to be able to edit data for three levels of hierarchy (parent object, parent's child object and collection of sub-child objects). My model roughly looks like: namespace MvcApplication1.Models { public class Parent { public int Id { get; set; } public string Name { get; set; } public Child Child { get; set; } } public class Child { public int Id { get; set; } public string Name { get; set; } public

Can i call a “shared” editor template from within a “areas” editor template, for the same model?

瘦欲@ 提交于 2020-01-13 08:31:27
问题 I've got an editor template location in: Areas/Posts/Views/Shared/EditorTemplates/Question.cshtml I also have one in: /Views/Shared/EditorTemplates/Question.cshtml For both, the model is the same. What i'm trying to do is within a View in the Posts area, call my editor template in the area, set some HTML and then bubble back up to the main shared editor template. Here's the Posts EditorTemplate: @model xxx.ViewModels.QuestionViewModel @Html.Hidden("Id", (byte)Model.QuestionType) @Html

Display a byte as a checkbox using a EditorTemplate?

白昼怎懂夜的黑 提交于 2020-01-11 13:20:13
问题 My model class: public class StatusList { public int StatusID {get;set;} [UIHint("ByteCheckbox")] public byte Active {get;set;} } In /Views/Shared/EditorTemplates I created a file called ByteCheckbox.cshtml The editortemplate ByteCheckbox contains (My 3rd attempt): @model byte @if (Model == 1) { @Html.CheckBox("", true) } else { @Html.CheckBox("", false) } Doing this nicely renders a checkbox. When I change the checkbox status and try to save the changes the model validation complains that

difference between: [ScaffoldColumn (false)] and [Display (AutoGenerateField = false)]

笑着哭i 提交于 2020-01-02 03:35:27
问题 To render HTML in my edit view, I use the helper @Html.EditorForModel() . My model: [Required(ErrorMessage = "Campo obrigatório")] [Display(Name = "Nome completo")] public string Name { get; set; } [Required(ErrorMessage = "Campo é obrigatório")] [StringLength(100, ErrorMessage = "A {0} deve ter pelo menos {2} characteres.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Senha")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirmar

Why is DropDownListFor not recognizing the selected value in my editor template?

人盡茶涼 提交于 2020-01-01 11:54:06
问题 I have the following editor template called 'DropDown.cshtml'. The list part works fine, and the template uses some voodoo I did to get the required SelectList from ViewData . The controller places all select lists in the view model into ViewData , and there is nothing wrong with the list side of things. @{ var list = this.GetModelSelectList(); } @Html.DropDownListFor(m => Model, list) I use this template on foreign key view model properties like this one: [Required] [UIHint("DropDown", "MVC"

IEnumerable model property in an ASP.NET MVC 3 Editor Template

拜拜、爱过 提交于 2020-01-01 05:52:07
问题 I have a model which has an IEnumerable property (warning pseudo-code to follow) public class PersonModel { public string Name { get; set; } public IEnumerable<AddressModel> Addresses { get; set; } } public class AddressModel { public string Name { get; set; } } I want to display the Address sub-objects in the same view Person.cshtml @model PersonModel <form> <h2>Person</h2> @Html.EditorFor(m=>m.Name) <ul>@Html.EditorFor(m=>m.Addresses)</ul> </form> EditorTemplate/AddressModel @model

Enum RadioButtonFor Editor Template set value

南笙酒味 提交于 2019-12-31 07:01:23
问题 Based on this question, I implemented a RadioButtonFor Editor Template. I works great but currently you cannot pass the value you want selected. EnumRadioButtonList.cshtml (Editor Template): @model Enum @foreach (var value in Enum.GetValues(Model.GetType())) { if ((int)value > 0) { @Html.RadioButtonFor(m => m, (int)value) @Html.Label(value.ToString()) } } I call it from View with: @Html.EditorFor(m => m.QuestionResponse, "EnumRadioButtonList") How do I pass the value QuestionResponse (enum)

Enum RadioButtonFor Editor Template set value

别说谁变了你拦得住时间么 提交于 2019-12-31 07:01:10
问题 Based on this question, I implemented a RadioButtonFor Editor Template. I works great but currently you cannot pass the value you want selected. EnumRadioButtonList.cshtml (Editor Template): @model Enum @foreach (var value in Enum.GetValues(Model.GetType())) { if ((int)value > 0) { @Html.RadioButtonFor(m => m, (int)value) @Html.Label(value.ToString()) } } I call it from View with: @Html.EditorFor(m => m.QuestionResponse, "EnumRadioButtonList") How do I pass the value QuestionResponse (enum)