Questions tagged [mvc-editor-templates]

ASP.NET-MVC EditorTemplates

379 questions
45
votes
2 answers

ASP.NET MVC 4 Editor Template for basic types

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…
Sam
  • 13,934
  • 26
  • 108
  • 194
39
votes
3 answers

How to use EditorFor inside a foreach

I have a model: public class MyListModel { public int ID {get;set;} public List Users{get;set;} } How do I use the Html.EditorFor method inside a foreach? @model MyListModel @foreach (var item in…
Jeremy
  • 44,950
  • 68
  • 206
  • 332
20
votes
7 answers

How to make a default editor template for enums?

How can I make a default editor template for enums? By which I mean: can I do something like this: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <% -- any code to read the enum and write a dropdown --> And put this…
Nour
  • 5,252
  • 3
  • 41
  • 66
19
votes
6 answers

MVC3 EditorTemplate for a nullable boolean using RadioButtons

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…
Nick Albrecht
  • 16,607
  • 10
  • 66
  • 101
18
votes
1 answer

ASP.NET MVC: Using EditorFor() with a default template for enums

I've written an EnumDropDownFor() helper which I want to use in conjunction with EditorFor(). I've only just started using EditorFor() so am a little bit confused about how the template is chosen. My Enum.cshtml editor template is below:
ajbeaven
  • 9,265
  • 13
  • 76
  • 121
17
votes
3 answers

ViewBag.Title value overrides Model.Title for ASP.NET MVC Editor Template

When I set ViewBag.Title at the top of a Razor template, the Model.Title editor template text box is populated using the value of ViewBag.Title instead of the expected Model.Title value. Calling Html.EditorFor(x => Model.Title) explicitly does not…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
16
votes
1 answer

Making my own HtmlHelper extension for input that works with model binding

I am unhappy with the current DropDownList implementation, because I can't really do much with the option tags (only selected, text and value is supported). I want to make my own where I can set disabled and other stuff on individual…
Inrego
  • 1,524
  • 1
  • 15
  • 25
15
votes
1 answer

Returning an EditorTemplate as a Partial View from a Controller

I would like to return an EditorTemplate from my controller as a Partial View. I am currently doing: public ActionResult Create([Bind(Prefix="Create")]CreateViewModel model) { return PartialView("~/Views/Shared/EditorTemplates/Template.cshtml",…
Dismissile
  • 32,564
  • 38
  • 174
  • 263
15
votes
3 answers

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

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…
Anthony Johnston
  • 9,405
  • 4
  • 46
  • 57
15
votes
4 answers

Change date format in ASP.NET MVC application

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:
Andrei
  • 42,814
  • 35
  • 154
  • 218
13
votes
1 answer

Put editor templates in view's folder with ASP.NET Core MVC 6

with MVC 4 I was able to put a view's editor templates into the view's folder: AwesomeApp/Views/UserMgmt/EditorTemplates/UserSettings.cshtml. Now I am using ASP.NET Core MVC 6 and it does not find the editor template. I have to put them into…
13
votes
2 answers

ASP.NET MVC editor template for property

Usually I render my forms by @Html.RenderModel, but this time I have a complex rendering logic and I render it manually. I decided to create a editor template for one property. Here is the code (copy pasted from default object editor template…
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266
12
votes
4 answers

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

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; } …
jrizzo
  • 1,652
  • 4
  • 17
  • 29
12
votes
3 answers

Ignore some fields using the helper @Html.EditorForModel()

I use helper @Html.EditorForModel() on all my views. There is a desire that he skip two fields in my model, but only on this view, the other he must continue to display these fields as usual. How can I skip these two fields only in this view?
ridermansb
  • 10,779
  • 24
  • 115
  • 226
12
votes
5 answers

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

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 =>…
JK.
  • 21,477
  • 35
  • 135
  • 214
1
2 3
25 26