mvc-editor-templates

Can i call a “shared” editor template from within a “areas” editor template, for the same model?

旧时模样 提交于 2019-12-05 03:08:39
I've got an editor template location in: Areas/Posts/Views/Shared/EditorTemplates/Question.cshtml I also have one in: /Views/Shared/EditorTemplates/Question.cshtml For both, the model is the same. What i'm trying to do is within a View in the Posts area, call my editor template in the area, set some HTML and then bubble back up to the main shared editor template. Here's the Posts EditorTemplate: @model xxx.ViewModels.QuestionViewModel @Html.Hidden("Id", (byte)Model.QuestionType) @Html.EditorForModel() But all it does it render out the hidden field, not the contents of the shared editor

EditorTemplate for List of complex type returns null, while EditorTemplate for its elements works fine

给你一囗甜甜゛ 提交于 2019-12-04 12:12:55
I have a View in which the user can choose any number of Clubs by selecting checkboxex. The Clubs are a property of the main model with type List <ClubModel >. While refactoring I start out with this: @using (Html.BeginForm()) { <fieldset> <legend>Voor Select clubs </legend><br /> <table> <tr> @for (var i = 0; i < Model.Clubs.Count; i++) { if (i % 3 == 0) { @:</tr><tr> } <td> @Html.HiddenFor(model => model.Clubs[i].ClubID) @Html.EditorFor(model => model.Clubs[i].IsAvailable) </td> <td>@Html.DisplayFor(model => model.Clubs[i].ClubName)</td> } </tr> </table> <input type="submit" value="Submit" /

Has the behavior for DataAnnotations in asp.net mvc 3 changed?

走远了吗. 提交于 2019-12-04 11:37:35
I have a Model with a property [ReadOnly(true)] public decimal BodyMassIndex { get; private set; } In my View when I call @Html.EditorForModel() I still get a standard editable textbox for that property Why is this? if the textbox is still editable whats the point of this DataAnnotation Attibute? Brad Wilson's post That is not a DataAnnotation attribute. Notice it's in the System.ComponentModel namespace. Data Annotations are in the System.ComponentModel.DataAnnotations namespace. However, this is a case where we could consider supporting it. But what exactly did you expect to happen and why

Why is DropDownListFor not recognizing the selected value in my editor template?

♀尐吖头ヾ 提交于 2019-12-04 09:50:26
I have the following editor template called 'DropDown.cshtml'. The list part works fine, and the template uses some voodoo I did to get the required SelectList from ViewData . The controller places all select lists in the view model into ViewData , and there is nothing wrong with the list side of things. @{ var list = this.GetModelSelectList(); } @Html.DropDownListFor(m => Model, list) I use this template on foreign key view model properties like this one: [Required] [UIHint("DropDown", "MVC", "SelectListName", "JobLevelSelectList")] [Display(Name = "Job Level")] public Guid? JobLevelId { get;

How to add and use a razor editor template

亡梦爱人 提交于 2019-12-04 05:23:38
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 Here is short info about adding EditorTemplate . In short words - you have to create directory EditorTemplates in Views/Shared and you should create a view with the same name as the model you want to create the editor for. Remember

Formatting currency using display template in MVC

为君一笑 提交于 2019-12-04 03:30:38
I found this post about Display and EditorTemplates for MVC: http://www.growingwiththeweb.com/2012/12/aspnet-mvc-display-and-editor-templates.html It creates a display template to easily display a decimal formatted with currency sign. The model used in the example: public class TestModel { public decimal Money { get; set; } } The display template: Views/Shared/DisplayTemplates/decimal.cshtml: @model decimal @{ IFormatProvider formatProvider = new System.Globalization.CultureInfo("en-US"); <span class="currency">@Model.ToString("C", formatProvider)</span> } In my website I have a helper class

DatePicker Editor Template

半城伤御伤魂 提交于 2019-12-03 17:09:53
Below is an EditorTemplate that renders a Bootstrap datetimepicker with EditorFor helpers, the problem I am seeing is with the script section. It works OK for one DateTimePicker per view - but since I am using class selector, whenever I use 2 or more DateTimePicker s per view it renders duplicate <script> sections, confusing the DOM as to on which TextBox to invoke the calendar. What am I missing here? @model DateTime? <div class='input-group date datePicker'> <span class="input-group-sm"> @Html.TextBox("", Model.HasValue ? Model.Value.ToString("d") : String.Empty) </span> </div> <script type=

How to automatically add placeholder attribute to html input type number in mvc 4?

假如想象 提交于 2019-12-03 12:53:14
问题 This is a very specific issue. I managed to automatically add the placeholder attribute to html5 email input type by using an editor template called EmailAddress.cshtml , saved in ~/Views/Shared/EditorTemplates/ folder. See the code below: @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "text-box single-line", placeholder = ViewData.ModelMetadata.Watermark }) It works because i'm using the [DataType(DataType.EmailAddress)] DataAnnotation in my view model. What

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

帅比萌擦擦* 提交于 2019-12-03 05:51:22
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 dictionary is null, but this dictionary requires a non-null model item of type 'System.Decimal'. My

How to automatically add placeholder attribute to html input type number in mvc 4?

▼魔方 西西 提交于 2019-12-03 03:07:23
This is a very specific issue. I managed to automatically add the placeholder attribute to html5 email input type by using an editor template called EmailAddress.cshtml , saved in ~/Views/Shared/EditorTemplates/ folder. See the code below: @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "text-box single-line", placeholder = ViewData.ModelMetadata.Watermark }) It works because i'm using the [DataType(DataType.EmailAddress)] DataAnnotation in my view model. What doesn't works is when I use a int? variable. public class MiageQuotaRequestViewModel { [Required] [DataType