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