editorformodel

EditorFor isn't working on derived type

只谈情不闲聊 提交于 2019-12-04 06:44:20
At least, I think that's related to the problem. My scenario is this: I've got a number of business entities with common fields, and each one has custom fields unique to that entity. So in code, this is modeled as an EntityBase class, and there are a number of classes derived from this, e.g., Derived . To make a reusable UI, I've got a view called EntityBase.vbhtml that looks like this: @ModelType EntityBase @Using Html.BeginForm("Edit", Model.GetType.Name) @* show the editor template for the derived type *@ @* !!the next line renders nothing!! *@ @Html.EditorFor(Function(x) Model, Model

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=

How to force Razor to make Editorfor to input number type for float variable?

本小妞迷上赌 提交于 2019-11-28 22:42:23
Here is my code in MVC 5: @Html.EditorFor(model => model.myfloatvalue, new { @type = "number", @min = "0", @step = "0.01", @value = "0" }) And here is the html code: <input class="text-box single-line" data-val="true" data-val-number="The field Fix Amount must be a number." data-val-required="The Fix Amount field is required." id="myfloatvalue" name="myfloatvalue" type="text" value=""> Not to <input class="text-box single-line" data-val="true" data-val-number="The field Fix Amount must be a number." data-val-required="The Fix Amount field is required." id="myfloatvalue" name="myfloatvalue"

Showing Different fields in EditorForModel vs. DisplayForModel modes in MVC2

家住魔仙堡 提交于 2019-11-28 19:44:27
I have a viewmodel that has an int StateID field and a string StateName field like so: public class DepartmentViewModel : BaseViewModel, IModelWithId { // only show in edit mode public int StateId { get; set; } // only show in display mode public string StateName { get; set; } } I have a read only view that uses DisplayForModel and an update view that uses EditorForModel . I want the DisplayForModel view to show the StateName property, and the EditorForModel view use the StateID property (I am actually rendering a dropdownlist based on this). I have not been able to figure out how to decorate

Showing Different fields in EditorForModel vs. DisplayForModel modes in MVC2

时光怂恿深爱的人放手 提交于 2019-11-27 12:30:18
问题 I have a viewmodel that has an int StateID field and a string StateName field like so: public class DepartmentViewModel : BaseViewModel, IModelWithId { // only show in edit mode public int StateId { get; set; } // only show in display mode public string StateName { get; set; } } I have a read only view that uses DisplayForModel and an update view that uses EditorForModel . I want the DisplayForModel view to show the StateName property, and the EditorForModel view use the StateID property (I