editortemplates

Passing model data to asp.net mvc EditorTemplates

ScottGu in this post link text shows how one can utilize EditorTemplates for things such as a Country DropDownList. My question is how can one pass a dynamic list of Countries to the EditorTemplate? ...

Returning an EditorTemplate as a PartialView in an Action Result - ASP.Net MVC 2

I have a model similar to this: public class myModel { public ClassA ObjectA {get; set;} public ClassB ObjectB {get; set;} } In my main view, I have tags similar to this: <div id="section1"> <%=Html.EditorFor(m => m.ObjectA)%> </div> <div id="section2"> <%=Html.EditorFor(m => m.ObjectB)%> </div> ClassA and ClassB b...

Conditional Editor template

How can we apply editor templates to selective rows in a grid? I want to show text box while editing for particular rows. I am using telerik grid. I have used [ReadOnly(true)] attribute for my class member and hence it's not showing me it as editable, which is obviously intended. But for selective rows, I want to show text box in my gr...

How can I validate the result in an ASP.NET MVC editor template?

I have created an editor template for representing selecting from a dynamic dropdown list and it works as it should except for validation, which I have been unable to figure out. If the model has the [Required] attribute set, I want that to invalidate if the default option is selected. The view model object that must be represented as t...

ASP.Net MVC 2 DropDownListFor in EditorTemplate

I have a view model that looks like this: namespace AutoForm.Models { public class ProductViewModel { [UIHint("DropDownList")] public String Category { get; set; } [ScaffoldColumn(false)] public IEnumerable<SelectListItem> CategoryList { get; set; } ... } } It has Category and Cate...

Asp.Net MVC EditorTemplate Model is lost after Post

I have a controller with two simple Methods: UserController Methods: [AcceptVerbs(HttpVerbs.Get)] public ActionResult Details(string id) { User user = UserRepo.UserByID(id); return View(user); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Details(User user) { return View(user); } Then there is one simple view for displayin...

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...

custom MVC2 editortemplates

i would like to create a library of custom EditorTemplates and DisplayTemplates. How do I "load" these into my MVC application? I want to be able to re-use my custom template library across a variety of MVC apps. ...

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

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...

Limit JavaScript and CSS files on ASP.NET MVC 2 Master Page based on Model and View content

I want to include certain .js and .css files only on pages that need them. For example, my EditorTemplate DateTime.ascx needs files anytimec.js and anytimec.css. That template is applied whenever I use either the EditorFor or EditorForModel helper methods in a view for a model with a DateTime type value. My technique: I've put this c...

setting displayname data annotation dynamically in asp.net mvc

I have a database table with the following fields item_key, item_value, display_name, uihint I want to be able to specify in the database table which displaytemplate to use and also the displayname. <%= Html.EditorFor(p=>pageField.item_value, pageField.uihint) %> The UIHint is working, but I can't work out a way of setting the disp...

Passing additional viewmodel data with EditorFor fails in one-to-many relatoinships

I have an editor template (Views/Shared/EditorTemplates/HORDER.ascx) which inherits System.Web.Mvc.ViewUserControl<CCOK2.Models.HORDER> My viewmodel has a one-to-many relationship which I use Html.EditorFor in order to render multiple HORDERS <%: Html.EditorFor(model => model.PEOPLE.HORDERS, new {fred="hello"})%> Eventually w...

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 => model.SomeNullableDecimal )%> The first one works fine, and loads the decimal editor te...

JSON / MVC (3P1) HttpPost - not getting it to work on my EF class

In mixing and matching older tutorials with recent posts on MVC 3 Preview 1, I run into the following problem. I am trying to move to JSON-driven edits of my Fighter model (and the underlying db) instead of 'plain old' edits without JSON. I have an edit view (that uses a Shared EditorTemplate, fighter.ascx) setup for my Fighter class (w...

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...

Checkboxes not working with MVC 2 editor templates and IE8

Iv created an editor template for the boolean type. And it works fine in all modern browsers expect IE8 where any value changes seem to be lost when they are posted to the server. I have read there are 'issues' with MVC checkboxs retaining their values, and as a result the Html.CheckBox helper includes a hidden field on the page to sto...

get value from custom attribute in editor template

at the moment I have this: in the ViewModel: [MyCustom(Foo = 23)] public int CountryId { get; set; } in the Editor template: <%= Html.TextBox("", Model) %> how can I get the value (Foo=23) from my custom attribute (MyCustom) into the editor template ? ...

How to get to the parent object in an editortemplate?

In a custom editor template I want to access the parent object. I'm using this code but this is probably not the best way to do it, especially when using nested views: object parent = ViewContext.Controller.ViewData.Model; Does anybody have a better idea? ...

Adding validation to a Dropdownlist in a EditorTemplate

Hello, I am trying to find a good way to have a dropdownlist by specifying UiHint "DropDown" to the property of the ViewModel and then just using HtmlHelper EditorFor to render the dropdown via an generic EditorTemplate so that it can be used across solutions. I found a very good approach by Tom Schreck Here It works fine. The only thi...