mvc-editor-templates

Display a byte as a checkbox using a EditorTemplate?

醉酒当歌 提交于 2019-12-02 12:35:37
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 the value is 'false' (or 'true') instead of the expected 0 or 1. How to modify the editortemplate to

Enum RadioButtonFor Editor Template set value

回眸只為那壹抹淺笑 提交于 2019-12-02 09:53:36
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) so that the radio button is selected? You can create a custom html helper which will give 2-way binding

IEnumerable in my ViewModel is not displayed with EditorForModel

孤街浪徒 提交于 2019-12-02 03:24:13
问题 ViewModel [Validator(typeof(ProdutoCategoriaValidator))] public class ProdutoCategoriaViewModel { [HiddenInput(DisplayValue = false)] public Guid ID { get; set; } public IEnumerable<SelectListItem> Tipos { get; set; } // <<<<------- Is not showing in my view [AdditionalMetadata("data-bind", "event: { change: function(data) { Link(data.Nome()); }}")] public string Nome { get; set; } [DataType(DataType.Url)] [AdditionalMetadata("Prefixo", "Produtos/{tipo-de-produto}#")] public string Link { get

IEnumerable in my ViewModel is not displayed with EditorForModel

痴心易碎 提交于 2019-12-02 02:15:49
ViewModel [Validator(typeof(ProdutoCategoriaValidator))] public class ProdutoCategoriaViewModel { [HiddenInput(DisplayValue = false)] public Guid ID { get; set; } public IEnumerable<SelectListItem> Tipos { get; set; } // <<<<------- Is not showing in my view [AdditionalMetadata("data-bind", "event: { change: function(data) { Link(data.Nome()); }}")] public string Nome { get; set; } [DataType(DataType.Url)] [AdditionalMetadata("Prefixo", "Produtos/{tipo-de-produto}#")] public string Link { get; set; } public int? Ordem { get; set; } public ProdutoCategoriaViewModel() { ID = Guid.NewGuid(); } }

EditorTemplate Naming Convention for Collection model classes

混江龙づ霸主 提交于 2019-12-02 01:29:18
I have a model property that is declared as type List<MyClass> . public class MyModel { List<MyClass> MyProperty { get; set; } } I want to be able to display/edit the property using Razor templates. My question is, how I name an EditorTemplate view so that I can display the property using the normal syntax: @model MyModel @Html.DisplayFor(m => m.MyProperty) I know that I can create a view called MyClass.cshtml that will be used for the type MyClass , but how do I create a template for the list? You could use the [UIHint] attribute: public class MyModel { [UIHint("TemplateForTheList")] public

Too many JavaScript and CSS files on my ASP.NET MVC 2 Master Page?

為{幸葍}努か 提交于 2019-12-01 11:02:15
I'm using an EditorTemplate DateTime.ascx in my ASP.NET MVC 2 project. <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %> <%: Html.TextBox(String.Empty, Model.ToString("M/dd/yyyy h:mm tt")) %> <script type="text/javascript"> $(function () { $('#<%: ViewData.TemplateInfo.GetFullHtmlFieldId(String.Empty) %>').AnyTime_picker({ format: "%c/%d/%Y %l:%i %p" }); }); </script> This uses the Any+Time™ JavaScript library for jQuery by Andrew M. Andrews III. I've added those library files ( anytimec.js and anytimec.css ) to the <head> section of my master page. Rather than

Can I Add to the Display/EditorTemplates Search Paths in ASP.NET MVC 3?

那年仲夏 提交于 2019-11-30 17:28:09
I have a standard set of templates for my mvc projects which I want to keep as an external folder in my source control (SVN) This means that I cannot put any project specific files in this folder as it will be committed to the wrong place.. .. and my standard templates need to override the ones that are used by MVC itself so they need to be in the place MVC expects overriding templates (e.g. ~/Views/Shared/EditorTemplates) So where can I put my project specific ones? Should I put them in ~/Views/Shared/SiteEditorTemplates, for example, and add the path to the search? How would I do that? Or an

Can I Add to the Display/EditorTemplates Search Paths in ASP.NET MVC 3?

两盒软妹~` 提交于 2019-11-30 16:48:23
问题 I have a standard set of templates for my mvc projects which I want to keep as an external folder in my source control (SVN) This means that I cannot put any project specific files in this folder as it will be committed to the wrong place.. .. and my standard templates need to override the ones that are used by MVC itself so they need to be in the place MVC expects overriding templates (e.g. ~/Views/Shared/EditorTemplates) So where can I put my project specific ones? Should I put them in ~

Change date format in ASP.NET MVC application

孤者浪人 提交于 2019-11-30 05:02:17
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.TextBox(string.Empty, (Model.HasValue ? Model.Value.ToString("dd.MM.yyyy") : string.Empty), new { @class =

MVC can't override EditorTemplate name when used in EditorFor for child object

ぐ巨炮叔叔 提交于 2019-11-30 00:48:45
I am trying to use an EditorTemplate to display a child collection in a table in the parent’s view. The problem I have run into is that this only seems to work if the template is named exactly the same as child’s class. When I attempt to use a template with a slightly different name, and pass that name as the templateName argument to EditorFor,I get a runtime error. I was hoping I could use different child EditorTemplates for different purposes with the same child collection. Here is an abbreviated example: Models: public class Customer { int id { get; set; } public string name { get; set; }