mvc-editor-templates

How to add and use a razor editor template

吃可爱长大的小学妹 提交于 2019-12-21 12:35:16
问题 I have tried to find documentation or samples on how to incorporate razor editor templates into a project. the following answer on another thread may fix a problem I am having but I do not know how to incorporate it into my project. It is no doubt easy. here is the solution I do not know how to incorporate: Client-side validation of input type date does not work 回答1: Here is short info about adding EditorTemplate . In short words - you have to create directory EditorTemplates in Views/Shared

ASP.NET MVC 2 - Html.EditorFor a nullable type?

ε祈祈猫儿з 提交于 2019-12-20 18:43:12
问题 I have two editor templates: one for decimal, and one for decimal? (nullable) But when I have a nullable decimal in my model, it tries to load the normal decimal editor: <%: Html.EditorFor(model => model.SomeDecimal )%> <%: Html.EditorFor(model => model.SomeNullableDecimal )%> The first one works fine, and loads the decimal editor template. The second one also tries to load the decimal template (and fails because it is not a decimal field). The error message is: The model item passed into the

How can I make Html.CheckBoxFor() work on a string field?

ぐ巨炮叔叔 提交于 2019-12-18 14:56:05
问题 I'm using ASP.NET MVC3 with Razor and C#. I am making a form builder of sorts, so I have a model that has a collection of the following object: public class MyFormField { public string Name { get; set; } public string Value { get; set; } public MyFormType Type { get; set; } } MyFormType is just an enum that tells me if the form field is a checkbox, or textbox, or file upload, or whatever. My editor template looks something like this (see the comment): ~/Views/EditorTemplates/MyFormField

ASP.NET MVC 4 Editor Template for basic types

房东的猫 提交于 2019-12-17 10:23:19
问题 I've created a template for Number input and if I do @Html.EditorFor(model => model.SomeValue, "Number") it works fine and the template is used. However that doesn't work: @Html.EditorFor(model => model.SomeValue) Why do I need to specify the name of the Editor Template for basic types ? 回答1: Editor templates work by convention. The name of the template must match the name of the type. So for example if SomeValue is an int type you could write a custom editor template at ~/Views/Shared

MVC3 Master-Details Validation not Displaying

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 02:43:32
问题 I have an MVC3 page with an object (Header) that has data and a list of objects (Details) that I want to update on a single page. On the details object I have custom validation (IValidatableObject) that also needs to run. This appears to generally be working as expected, validations are running and returning ValidationResults and if I put an @Html.ValidationSummary(false); on the page it displays those validations. However I don't want a list of validations at the top, but rather next to the

ASP.net MVC - Using EditorFor with the same model type twice

六眼飞鱼酱① 提交于 2019-12-13 12:16:16
问题 I have the following model in MVC: public class IndexViewModel { public SubViewModel SubViewModel { get; set; } } In my Index view I am doing the following to display an Editor for SubViewModel : Index.cshtml @model IndexViewModel @Html.EditorFor(m => m.SubViewModel) In my SubViewModel.cshtml file I tried to do the following: EditorTemplates/SubViewModel.cshtml @model SubViewModel @Html.EditorForModel("SubViewModelForm") Basically, I want to split apart my Editor into two pieces. The first

DisplayTemplate not working for nullable DateTime

≯℡__Kan透↙ 提交于 2019-12-13 04:53:59
问题 Below is the the display template I created for a nullable DateTime property. I have this stored in the Views\Shared\EditorTemplates folder. The name of this template is DisplayNullableDate.cshtml . @model DateTime? @Html.Label("", (Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : string.Empty), new { @class = "form-control" }) I am calling this template like so on my Details page, however it's not working. I'm still getting the time when it's displayed on the web page. <tr> <td>@Html

MVC Collection Missing items on Post

不羁的心 提交于 2019-12-12 06:01:12
问题 I've recently run into some behaviour with MVC4 that I'm hoping to gain some perspective on. The behaviour in my actual project uses more complex objects, but I was able to replicate it with simple objects, which is what I'm using in this question. My situation is as follows: I have a View that uses a Collection of strings as its model. I'm calling "EditorFor" to display each string in the collection. In the controller, I am populating the model with 7 string items and passing it to the view.

How to provide an EditorTemplate for IEnumerable<MyModel>?

拥有回忆 提交于 2019-12-12 01:49:41
问题 Is it possible to provide an Editor Template for IEnumerable (Or IList, List, MyModel[], for that matter)? 回答1: I know this is a old post but what you can do is make a template called MyModelList that takes IEnumerable<MyModel> and then you can have a Html.EditorFor(x => x.MyModelList, "MyModelList") 来源: https://stackoverflow.com/questions/6460460/how-to-provide-an-editortemplate-for-ienumerablemymodel

Asp.Net MVC 5 Html.DropDownList is not validating

有些话、适合烂在心里 提交于 2019-12-12 01:37:34
问题 I've been stuck on this problem for a while now and can't seem to find anything online that helps. I have a Html.DropDownList in an Editor Template. I use that template in my form and don't select anything for the dropdownlist. When I click submit, I expect the form to notify me that the required dropdownlist doesn't have a value selected, but it doesn't. What am I doing wrong? Here are the View Models: public class RequestCreateViewModel { public int ID { get; set; } public