editorformodel

Display EditorFor() value as Read-Only on MVC View?

落花浮王杯 提交于 2020-05-14 19:56:49
问题 I have several fields I display on most of my views in my MVC5 Code-First app: [created_date] , [created_by] , [modified_date] , and [modified_by] . For the user, I would like to include these also on my Edit() view, but unlike my other fields I do not wish to have them editable (commonly created/by and modified/by data should NOT be editable). This is how I have the fields declared on my Edit() view currently: <div class="form-group"> @*@Html.LabelFor(model => model.created_date,

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

Remove default value for non nullable properties when using EditFor [asp.net mvc 3]

偶尔善良 提交于 2019-12-24 07:46:24
问题 How can I remove the default value that is added by default to the textboxes of non nullable properties when using the EditFor helper? I don't want that behavior EDIT Sorry I didn't give enough information. For example if you use Html.EditorFor with a property that is DateTime it will set the textbox value to 1/1/0001 automatically. If you use "DateTime?"(nullable), it won't, it just leaves the textbox empty. 回答1: You can use UIHint to do it. Create a file called ShortDate.cshtml in

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

心已入冬 提交于 2019-12-18 01:31:12
问题 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

Make EditorFor render decimal value as type=“text” not type=“number”

大兔子大兔子 提交于 2019-12-13 00:25:21
问题 I have two properties in a model class: public int? IntTest { get; set; } public decimal? DecimalTest { get; set; } Which I then render with: @Html.EditorFor(model => model.IntTest, new { htmlAttributes = new { @class = "form-control"} }) @Html.EditorFor(model => model.DecimalTest, new { htmlAttributes = new { @class = "form-control"} }) I'd expected both of them to render as html inputs of type number, but the decimal one doesn't, I get: <input class="form-control text-box single-line" data

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

Displaying complex types in ASP.NET MVC3 RC2

孤人 提交于 2019-12-07 07:00:25
问题 I have a model that uses a complex type as a property. namespace Web.Models { public class Business : IModel { [Key, HiddenInput(DisplayValue = false)] public Guid ID { get; set; } public Position Position { get; set; } public bool Active { get; set; } public ICollection<Comment> Comments { get; set; } public Business() { ID = Guid.NewGuid(); Position = new Position(); } } public class Position { public double Latitude { get; set; } public double Longitude { get; set; } } } When I came to

EditorFor isn't working on derived type

≡放荡痞女 提交于 2019-12-06 01:07:25
问题 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

Displaying complex types in ASP.NET MVC3 RC2

夙愿已清 提交于 2019-12-05 18:20:12
I have a model that uses a complex type as a property. namespace Web.Models { public class Business : IModel { [Key, HiddenInput(DisplayValue = false)] public Guid ID { get; set; } public Position Position { get; set; } public bool Active { get; set; } public ICollection<Comment> Comments { get; set; } public Business() { ID = Guid.NewGuid(); Position = new Position(); } } public class Position { public double Latitude { get; set; } public double Longitude { get; set; } } } When I came to create a form of the Business model, the Position property wasn't displayed. I'm sure complex types were

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