editorfor

Rendering the field name in an EditorTemplate (rendered through EditorFor())

I'm currently building the Admin back-end for a website in ASP.NET MVC. In an ASP.NET MVC application, I've started using the 'EditorFor' helper method like so: <div id="content-edit" class="data-form"> <p> <%= Html.LabelFor(c => c.Title) %> <%= Html.TextBoxFor(c => c.Title)%> </p> <p> <%= Html.Label...

Using EditorFor<> to render a drop-down list

So far we can use Html.EditorFor() to dynamically render the appropriate template for a datatype - e.g. string, int, or a custom type, say 'Address'. Now I want to use EditorFor() to render a 'Parent' field. I want a drop-down containing every row, and the user picks a parent from this drop-down. The 'Parent' template has access to the...

Override EditorForModel Template

Hi, You can provide alternate templates for individual types, but is it possible to override the template that wraps the label, field and validation up. Change: <div class="editor-label"><label for="Content">Content</label></div> <div class="editor-field"><input class="text-box single-line" id="Content" name="Content" type="text" valu...

ASP.NET MVC UI Template: How to mix an IList Model property with EditorFor( m => m.subModel)?

Say you have this: public class ShoppingCart { public IList<CartItem> cartItems {get; set; } } And you do this to render the class: <%= EditorFor( m => m.ShoppingCart, "ShoppingCart") %> How would you do the EditorFor( ??, "CartItem") in the ShoppingCart.ascx? I would think it would look something like this: <% foreach( CartI...

ASP.Net MVC 2.0: EditorFor setting name via attributes

Hey guys Just wondering how do I mimic the following using attributes... <%= Html.EditorFor(x => x.SportProgramIdList, "FormMultiSelectDropDownList", "SportProgramIds")%> I know I can specify the template by using [UIHint("FormMultiSelectDropDownList")] but I am left with the problem with how to set the name... Cheers Anthony ...

ASP.NET MVC 2 RC: How to use the EditorFor to render correct name attributes for a List<>?

In the MVC RC 2 docs, we find: Expression-based helpers that render input elements generate correct name attributes when the expression contains an array or collection index. For example, the value of the name attribute rendered by Html.EditorFor(m => m.Orders[i]) for the first order in a list would be Orders[0]. Anyone care to lin...

How to set order of appearance for fields when using Html.EditorFor in MVC 2?

I have the following classes in my Model: public abstract class Entity : IEntity { [ScaffoldColumn(false)] public int Id { get; set; } [Required,StringLength(500)] public string Name { get; set; } } and public class Model : SortableEntity { [Required] public ModelType Type { get; set; } [ListRequired] ...

Unexpected Html.EditorFor behavior in ASP.NET MVC 2

I am getting some unexpected behavior from Html.EditorFor(). I have this controller: [HandleError] public class HomeController : Controller { [AcceptVerbs(HttpVerbs.Get)] public ActionResult Lister() { string[] values = { "Hello", "world", "!!!" }; return View(values); } [AcceptVerbs(HttpVerbs.Post...

.Net MVC UserControl - RenderPartial or EditorFor

Hi I have a View that contains a usercontrol. The usercontrol is rendered using: <% Html.RenderPartial("GeneralStuff", Model.General, ViewData); %> My problem is that the usercontrol renders nicely with values from the model but when I post values edited in the usercontrol they are not mapped back to Model.General. I know I can find ...

Hide editor-label for public property when calling EditorFor(...)?

When calling Html.EditorFor(m => m), where m is a public class with public properties, a hidden input and a label are displayed for properties with the [HiddenInput] attribute. How can I hide the label without making it private or creating an editor template? Example public class User { [HiddenInput] public Guid ID { get; s...

ForEach with EditorFor

I have got an Entity model which contains a collection of Message objects which are of the type Message which has several properties, including content, MessageID, from, and to. I have created an EditorTemplate for type Message, however, I cannot get it to display the contents of the Messages collection. There are no errors, but nothin...

How to bind Lists of a custom view model to a dropDownList an get the selected value after POST in ASP.NET MVC?

I have following problem. In my view model I defined some list properties as follows: public class BasketAndOrderSearchCriteriaViewModel { List<KeyValuePair> currencies; public ICollection<KeyValuePair> Currencies { get { if (this.currencies == null) this.currencies = new List<KeyV...

How to disable input field's autocomplete with EditorFor?

<%= Html.EditorFor(product => product.Name) %> I need the generated output to have autocomplete="off" attribute set. What I'm missing? Edit: I'm looking an extension method for EditorFor that accepts key/value dictionary for attributes, so I can call it like this: <%= Html.EditorFor(product => product.Name, new { autocomplete = "off"...

MVC 2 Templates - Is it possible to redirect the current editor template to its display template based on metadata?

For a project I'm working I've been asked to redirect an editor template to its display template based on metadata that is provided with the model. Now I was looking at a way to do it before it hits the editor template but that seems to cause more issues than it is worth, at least with how the system has been architected. The simplest ...

Define EditorTemplate for child collection in viewmodel

I've got a model which contains a List of QuestionEditModel for which I want to use an EditorFor. Normally, I would just call EditorFor on the collection and MVC will do the rest. However, I need the individual QuestionEditModel to use different EditorTemplates depending on the value of a field within the object. I would've thought tha...

asp mvc 2 EditorFor strange behavior

ok i've defined a shared editor for string like the following <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <%= Html.LabelFor(model => model) %> <%= Html.TextBoxFor(model => model) %> <%= Html.ValidationMessageFor(model => model) %> now i'm calling the custom editor like ...

EditorFor with a variable length list - wrong data is displayed after deleting an item

I'm trying to create a form which will be used by clients to place an order for variable amount of models. It's similar to example from Steve Sanderson's blog, but I'm not using any javascript - I just have multiple submits in my form. Everything works fine, I can add as many items as I want, but when I delete an item always the last on...

Html attributes for EditorFor() in ASP.NET MVC

Why can't I pass in html attributes to EditorFor()? eg; <%= Html.EditorFor(model => model.Control.PeriodType, new { disabled = "disabled", readonly = "readonly" }) %> I don't want to use metadata Update: The solution was to call this from the view : <%=Html.EditorFor( model => model.Control.PeriodEndDate, new {Modifiable=mode...

ASP NET mvc 2 Template for EditorFor and DisplayFor

I would like to control or customise the output generated by DisplayFor and EditorFor so it doesn't render the default html css tags for example: ....... I would like this to be for all views not just a type or system type? And what is the simplest solution? Any help would be appreciated. ...

MVC EditorFor inside Another EditorFor

I have an EditorFor Template for a Model Role as below. I also have EditorFor for Date which works fine when I use EditorFor directly from View but when I have EditoFor inside an editor for it doesn't work. Any idea? Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl[ucsrManagementSystem.Models.ContactsInMailingListsViewMode...