editortemplates

Display a byte as a checkbox using a EditorTemplate?

白昼怎懂夜的黑 提交于 2020-01-11 13:20:13
问题 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

mvc3, editor template, css clas, maxlength and size

瘦欲@ 提交于 2020-01-11 12:07:56
问题 I have an editor template as following but class, maxlength and size attributes are not getting to the source. @using System.Globalization @model DateTime? @Html.TextBox("", (Model != null && Model.HasValue && !Model.Value.ToString(CultureInfo.InvariantCulture).Contains("1900") && !Model.Value.ToString(CultureInfo.InvariantCulture).Contains("0001") ? Model.Value.ToString("MM/dd/yyyy") : string.Empty), new { @class = "datePicker", maxlength = "12", size = "12" }) I have changed it to following

mvc3, editor template, css clas, maxlength and size

烂漫一生 提交于 2020-01-11 12:07:21
问题 I have an editor template as following but class, maxlength and size attributes are not getting to the source. @using System.Globalization @model DateTime? @Html.TextBox("", (Model != null && Model.HasValue && !Model.Value.ToString(CultureInfo.InvariantCulture).Contains("1900") && !Model.Value.ToString(CultureInfo.InvariantCulture).Contains("0001") ? Model.Value.ToString("MM/dd/yyyy") : string.Empty), new { @class = "datePicker", maxlength = "12", size = "12" }) I have changed it to following

IEnumerable model property in an ASP.NET MVC 3 Editor Template

拜拜、爱过 提交于 2020-01-01 05:52:07
问题 I have a model which has an IEnumerable property (warning pseudo-code to follow) public class PersonModel { public string Name { get; set; } public IEnumerable<AddressModel> Addresses { get; set; } } public class AddressModel { public string Name { get; set; } } I want to display the Address sub-objects in the same view Person.cshtml @model PersonModel <form> <h2>Person</h2> @Html.EditorFor(m=>m.Name) <ul>@Html.EditorFor(m=>m.Addresses)</ul> </form> EditorTemplate/AddressModel @model

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

喜欢而已 提交于 2019-12-30 11:41:29
问题 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

IEnumerable property with MVC3 EditorTemplate

痞子三分冷 提交于 2019-12-24 15:01:21
问题 Similar to this post IEnumerable model property in an ASP.NET MVC 3 Editor Template, I have Model public class Student { public int StudentId { get; set; } public string StudentName{ get; set; } //FYI..Its virtual because of EF relationship public virtual ICollection<Class> Classes{ get; set; } } public class Class { public int ClassId { get; set; } public string ClassName{ get; set; } } View - EditStudent @model Student @Html.TextBoxFor(m => m.StudentName) //I get the error for following.

Storing Editor Templates in external library

佐手、 提交于 2019-12-22 11:29:11
问题 Is it possible to create Editor Templates in an external library so that they can be shared between applications? I'm not looking to store cshtml files in a library, just wondering if there was a way you can create them and store them like you do with html helpers. There are a few that i use quite a lot and it would be nice to have them all in a single library to reference. 回答1: MVCContrib Portable Areas offers this functionality. Out of the box there is nothing built-in. You will need to

Asp.net MVC with Entity, using jquery to pass data into List. Does not work

主宰稳场 提交于 2019-12-22 08:39:39
问题 Edit 3 / Final This is the fully working example using .NET MVC, Jquery and editor templates. https://www.dropbox.com/s/t4yxbhkuowyd7va/exerciseTest.rar Edit 2 It finally works ! Thanks to the answer below. It appears that i needed to change the NewAnswerRow partial line: <input type='text' id='Answers_@(Model.AnswerId)__Answer' name='Answers[@Model.AnswerId].Answer'/> Thanks ! Edit 1: I've followed this guide: http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding

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

ASP.NET MVC 3 Generic DisplayTemplates

落爺英雄遲暮 提交于 2019-12-19 18:31:38
问题 I've just started a project using ASP.NET MVC 3. I'm building on top of an existing object system, so one of the first things I have to do is define display and editor templates for the various types that exist. Is it possible in MVC to define a DisplayTemplate with a generic argument? For example, we have a BitString<T> class which takes an enumeration as the generic argument and represents a list of options wrapping the supplied enumeration. I'm hoping I can define a single Display/Editor