mvc-editor-templates

Official “How to” for MVC Editor/Display Templates?

一世执手 提交于 2019-11-29 09:32:09
I have been using MVC Editor & Display Templates for a while, but have come to realize that there seems to be very little official documentation on MVC Editor/Display Templates (Html.EditorFor() and Html.DisplayFor()). I found the basic MSDN documentation just showing the technical details (which on their own, are not very helpful), but I'm looking more for an official how-to, sort of like this example . Are Editor/Display Templates more of an afterthought, and not really widely enough used to justify more in-depth official documentation? Or, am I blind, and what I'm looking for exists, I just

Change date format in ASP.NET MVC application

核能气质少年 提交于 2019-11-29 02:48:24
问题 I need to change date format to be dd.MM.yyyy . I am getting client side validation error because ASP.NET MVC date format is different from what I expect on the server. In order to change ASP.NET MVC date format I tried: Web.config: <globalization uiCulture="ru-RU" culture="ru-RU" /> Model: [DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true)] public DateTime? ServiceCreatedFrom { get; set; } Editor template: @model DateTime? @Html

Official “How to” for MVC Editor/Display Templates?

一世执手 提交于 2019-11-28 03:05:02
问题 I have been using MVC Editor & Display Templates for a while, but have come to realize that there seems to be very little official documentation on MVC Editor/Display Templates (Html.EditorFor() and Html.DisplayFor()). I found the basic MSDN documentation just showing the technical details (which on their own, are not very helpful), but I'm looking more for an official how-to, sort of like this example. Are Editor/Display Templates more of an afterthought, and not really widely enough used to

How to create an EditorTemplate for bootstrap checkbox?

∥☆過路亽.° 提交于 2019-11-28 02:03:38
I am working with a bootstrap template and its checkbox template is like this: <div class="checkbox"> <label> <input type="checkbox" class="checkbox style-1" checked="checked"> <span>Checkbox 1</span> </label> </div> I need an MVC EditorTemplate for boolean values to use this template. MVC CheckBoxFor default template is not like this template, it has another hidden input field to hold data and there is no span to show checkbox icon (it uses a default icon not stylable by css). MVC CheckBoxFor default template : <input checked="checked" data-val="true" data-val-required="required." id=

MVC3 EditorTemplate for a nullable boolean using RadioButtons

倾然丶 夕夏残阳落幕 提交于 2019-11-27 20:08:47
I have a property on one of my objects that is a nullable boolean, I want my logic to have true represent Yes, false to be No and null to be N/A. Now because I am going to have multiple properties like this on many different objects it makes the most sense to make an editor and display templates for these properties. I am going to use jQuery UI to apply a visual element of buttonset after this is all working but for now, that's beyond the scope of my problem. My editor template looks like this. @model bool? <div data-ui="buttonset"> @Html.RadioButtonFor(x => x, true, new { id = ViewData

How to use EditorFor inside a foreach

廉价感情. 提交于 2019-11-27 12:36:30
I have a model: public class MyListModel { public int ID {get;set;} public List<User> Users{get;set;} } How do I use the Html.EditorFor method inside a foreach? @model MyListModel <table> <tr> <th></th> </tr> @foreach (var item in Model.Users) { <tr> <td> @Html.EditorFor(item.Enabled) </td> </tr> } </table> @Html.EditorFor(x=> item.Enabled) It's been pointed out many times that posting such a model back to server will not work in mvc by default. For properly editing with EditorFor in a loop - for should be used as in: @for(var i = 0; i< Model.Users.Count;i++){ Html.EditorFor(i=>Model.Users[i])

ASP.NET MVC 4 Editor Template for basic types

强颜欢笑 提交于 2019-11-27 11:19:05
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 ? Darin Dimitrov 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/EditorTemplates/Int32.cshtml which will be used. In this case all integer types will use this

MVC3 EditorTemplate for a nullable boolean using RadioButtons

你说的曾经没有我的故事 提交于 2019-11-26 22:53:58
问题 I have a property on one of my objects that is a nullable boolean, I want my logic to have true represent Yes, false to be No and null to be N/A. Now because I am going to have multiple properties like this on many different objects it makes the most sense to make an editor and display templates for these properties. I am going to use jQuery UI to apply a visual element of buttonset after this is all working but for now, that's beyond the scope of my problem. My editor template looks like

How to create an EditorTemplate for bootstrap checkbox?

心已入冬 提交于 2019-11-26 22:09:42
问题 I am working with a bootstrap template and its checkbox template is like this: <div class="checkbox"> <label> <input type="checkbox" class="checkbox style-1" checked="checked"> <span>Checkbox 1</span> </label> </div> I need an MVC EditorTemplate for boolean values to use this template. MVC CheckBoxFor default template is not like this template, it has another hidden input field to hold data and there is no span to show checkbox icon (it uses a default icon not stylable by css). MVC

How to use EditorFor inside a foreach

 ̄綄美尐妖づ 提交于 2019-11-26 16:05:06
问题 I have a model: public class MyListModel { public int ID {get;set;} public List<User> Users{get;set;} } How do I use the Html.EditorFor method inside a foreach? @model MyListModel <table> <tr> <th></th> </tr> @foreach (var item in Model.Users) { <tr> <td> @Html.EditorFor(item.Enabled) </td> </tr> } </table> 回答1: @Html.EditorFor(x=> item.Enabled) It's been pointed out many times that posting such a model back to server will not work in mvc by default. For properly editing with EditorFor in a