mvc-editor-templates

mvc3 razor editortemplate with abstract classes

∥☆過路亽.° 提交于 2019-12-07 04:14:02
问题 this is a follow up question from MVC3 Razor httppost return complex objects child collections. The example I gave was very simple. The child collection is actually a collection of objects that all come from an abstract base class. So the collection has a list of base classes. I have created a template for each derived class and tried using if child is of type then give the template name as a string. The templates are rendered to the view but not populated on the post back. I am not sure how

Properly registering JavaScript and CSS in MVC 2 Editor Templates

吃可爱长大的小学妹 提交于 2019-12-07 02:10:42
问题 How do I properly register javascript blocks in an ASP.NET MVC 2 (RTM) Editor template? The specific scenario I'm in is that I want to use Dynarch JSCal2 DateTimePicker for my standard datetime picker, but this question is in general to any reusable javascript package. I have my template working properly now but it has my JS and CSS includes in my master page and I would rather only include these things if I actually need them: <link rel="stylesheet" type="text/css" href="../../Content/JSCal2

ASP.NET MVC 4 - EditorTemplate for nested collections

风流意气都作罢 提交于 2019-12-06 09:11:35
I have the following model classes (classes simplifies for the purpose of this question): public class Lesson { public Guid Id {get;set;} public string Name {get;set;} public List<ExerciseForPupil> Exercises {get;set;} } public class ExerciseForPupil { public Guid Id {get;set;} public string Name {get;set;} public List<ExerciseItemForPupil> ExerciseItems {get;set;} } public class ExerciseItemForPupil { public Guid Id {get;set;} public string Content {get;set;} public string UserValue {get;set;} } Now, I want users to be able to fille "UserValue" value for each exercise in the lesson. Let's say

Has the behavior for DataAnnotations in asp.net mvc 3 changed?

只谈情不闲聊 提交于 2019-12-06 05:31:30
问题 I have a Model with a property [ReadOnly(true)] public decimal BodyMassIndex { get; private set; } In my View when I call @Html.EditorForModel() I still get a standard editable textbox for that property Why is this? if the textbox is still editable whats the point of this DataAnnotation Attibute? Brad Wilson's post 回答1: That is not a DataAnnotation attribute. Notice it's in the System.ComponentModel namespace. Data Annotations are in the System.ComponentModel.DataAnnotations namespace.

MVC3 Razor Editor/Display templates and generics

廉价感情. 提交于 2019-12-06 00:46:17
There were a few questions regarding mvc templates and generics however there seems to be none related to what I'm looking for. Consider the following models: namespace MyNamespace { public class ModelBase { /* Not important for example */ } public class MyModel : ModelBase { public string Name { get; set; } } public class MyViewModel { public IEnumerable<ModelBase> Data { get; set; } } } And a controller: public class HomeController : Controller { public ActionResult Index { return View(new MyViewModel { Data = new List<MyModel>() }) } } A Razor view Views/Home/Index.cshtml would look like:

Formatting currency using display template in MVC

余生颓废 提交于 2019-12-05 19:51:56
问题 I found this post about Display and EditorTemplates for MVC: http://www.growingwiththeweb.com/2012/12/aspnet-mvc-display-and-editor-templates.html It creates a display template to easily display a decimal formatted with currency sign. The model used in the example: public class TestModel { public decimal Money { get; set; } } The display template: Views/Shared/DisplayTemplates/decimal.cshtml: @model decimal @{ IFormatProvider formatProvider = new System.Globalization.CultureInfo("en-US");

ASP.NET MVC editor template for property

冷暖自知 提交于 2019-12-05 14:57:58
问题 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 implementation): <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <% var modelMetadata = ViewData.ModelMetadata; %> <% if (modelMetadata.HideSurroundingHtml) { %> <%= Html.Editor(modelMetadata.PropertyName) %> <% } else { %> <% if (

Asp.Net MVC3 Razor - child items list not posting back from editor

一曲冷凌霜 提交于 2019-12-05 14:16:36
I'm trying to create a multi-level editor in MVC3. By multi-level I mean that I would like to be able to edit data for three levels of hierarchy (parent object, parent's child object and collection of sub-child objects). My model roughly looks like: namespace MvcApplication1.Models { public class Parent { public int Id { get; set; } public string Name { get; set; } public Child Child { get; set; } } public class Child { public int Id { get; set; } public string Name { get; set; } public IEnumerable<SubChild> SubChildren { get; set; } } public class SubChild { public int Id { get; set; } public

Properly registering JavaScript and CSS in MVC 2 Editor Templates

喜欢而已 提交于 2019-12-05 07:22:41
How do I properly register javascript blocks in an ASP.NET MVC 2 (RTM) Editor template? The specific scenario I'm in is that I want to use Dynarch JSCal2 DateTimePicker for my standard datetime picker, but this question is in general to any reusable javascript package. I have my template working properly now but it has my JS and CSS includes in my master page and I would rather only include these things if I actually need them: <link rel="stylesheet" type="text/css" href="../../Content/JSCal2-1.7/jscal2.css" /> <link rel="stylesheet" type="text/css" href="../../Content/JSCal2-1.7/border-radius

difference between: [ScaffoldColumn (false)] and [Display (AutoGenerateField = false)]

点点圈 提交于 2019-12-05 06:33:19
To render HTML in my edit view, I use the helper @Html.EditorForModel() . My model: [Required(ErrorMessage = "Campo obrigatório")] [Display(Name = "Nome completo")] public string Name { get; set; } [Required(ErrorMessage = "Campo é obrigatório")] [StringLength(100, ErrorMessage = "A {0} deve ter pelo menos {2} characteres.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Senha")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirmar senha")] [Compare("Password", ErrorMessage = "A nova senha e a confirmação da senha não conincidem.")]