editortemplates

ASP.NET MVC 3 Generic DisplayTemplates

我的梦境 提交于 2019-12-19 18:31:12
问题 I've just started a project using ASP.NET MVC 3. I'm building on top of an existing object system, so one of the first things I have to do is define display and editor templates for the various types that exist. Is it possible in MVC to define a DisplayTemplate with a generic argument? For example, we have a BitString<T> class which takes an enumeration as the generic argument and represents a list of options wrapping the supplied enumeration. I'm hoping I can define a single Display/Editor

How to create custom editor/display templates in ASP.NET MVC 3?

喜夏-厌秋 提交于 2019-12-17 03:01:35
问题 I would like to make custom editor templates for different data types in ASP.NET MVC (to use with Html.EditorFor() ), including rewriting the existing templates. The ultimate goal is to create a mini-framework where each editor supports javascript notifications about being changed, and I can show a message to the user that there are unsaved changes in the page. (Maybe there's something existing already?) I can find many questions pertaining to problems with such templates, but nowhere can I

ASP.NET MVC 3 - Partial vs Display Template vs Editor Template

送分小仙女□ 提交于 2019-12-17 02:30:22
问题 So, the title should speak for itself. To create re-usable components in ASP.NET MVC, we have 3 options (could be others i haven't mentioned): Partial View: @Html.Partial(Model.Foo, "SomePartial") Custom Editor Template: @Html.EditorFor(model => model.Foo) Custom Display Template: @Html.DisplayFor(model => model.Foo) In terms of the actual View/HTML, all three implementations are identical: @model WebApplications.Models.FooObject <!-- Bunch of HTML --> So, my question is - when/how do you

MVC 3 - Editor template for List<> Model [closed]

廉价感情. 提交于 2019-12-13 16:02:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am building my first Razor app and really loving it. I am trying to get the low-down on how to create an editor template that renders out an editable list of items without a foreach loop. Is this possible? Here are the basics of what I am trying to achieve: In my view (Views/Image/Homepage.cshtml) I have:

setting displayname data annotation dynamically in asp.net mvc

心不动则不痛 提交于 2019-12-11 23:17:32
问题 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 displayname dynamically, the above code is producing something like item_value TEXTBOX item_value TEXTBOX item_value TEXTBOX Where I want the item_values titles to be

Bind model during post of form inside EditorTemplate (on array)/multiple bind prefixes?

夙愿已清 提交于 2019-12-11 16:03:05
问题 I have a complex Model containing an array. For rendering items for this array I'm using EditorFor like this: for (int i = 0; i < Model.Contacts.Phones.Length; i++) { @Html.EditorFor(x => x.Contacts.Phones[i]) } Inside editor there is a post-form. Problem is, that binding is successful only when I exactly specify binding prefix: [HttpPost] public ActionResult SavePhone( [Bind(Prefix = "Contacts.Phones[0]")]Contact5UsedPhone model) { ... } So it works only for first of the elements. What is

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

佐手、 提交于 2019-12-11 14:08:24
问题 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 condition into the <head> section of my master page. It checks for a DateTime type property in the ModelMetadata. <% if (this.ViewData.ModelMetadata.Properties

Cannot use TypeConverter and custom display/editor template together?

可紊 提交于 2019-12-11 03:45:36
问题 The scenario Suppose I have the following two model classes: public class ProductColor { public long Id { get; set; } public string Name { get; set; } } public class Product { public long Id { get; set; } public string Name { get; set; } public long ProductColorId { get; set; } public virtual ProductColor ProductColor { get; set; } } Now in a form for creating a new product, I might have this line for the color field... @Html.EditorFor(model => model.ProductColor) I want this to generate a

Problem with MVC EditorFor named template

余生颓废 提交于 2019-12-08 22:53:50
问题 I have what appears (to me anyway) to be a strange problem... I created a simple editor template for a SelectListItem (SelectListItem.cshtml in the ~/Views/Shared/EditorTemplates folder), for example: <ul class="select-list-item cell-15 col-3 omega clearfix"> @Html.EditorFor(c => c.Categories) </ul> Where c.Categories is an IEnumerable This worked fine, but I wanted another template to render the collection with slightly different markup, so I copied and renamed the editor template to, for

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

时间秒杀一切 提交于 2019-12-08 03:03:56
问题 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 (which exists in an EF 4 model). On this I have 2 buttons. One 'old' one, which is a submit that calls my editcontroller without JSON, and one is a new one,