editortemplates

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

别等时光非礼了梦想. 提交于 2019-12-06 10:49:09
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, for which I've written a new HttpPost ActionResult The old button works: the new button is only half

ModelMetadata for complex type in editortemplate in asp.net mvc

送分小仙女□ 提交于 2019-12-06 02:57:19
问题 I have a viewmodel that includes a complex property of type TestThing which is declared as: public class TestThing { [Display(Name = "String3", Prompt = "String4")] public string Test1 { get; set; } [Display(Name = "String5", Prompt = "String6")] public string Test2 { get; set; } } I have an EditorTemplate for this type in which I would like to be able to access the meta data for each of the child properties. If the template was for a string for example, I could access the Prompt text by

Asp.net MVC with Entity, using jquery to pass data into List. Does not work

…衆ロ難τιáo~ 提交于 2019-12-05 14:54:28
Edit 3 / Final This is the fully working example using .NET MVC, Jquery and editor templates. https://www.dropbox.com/s/t4yxbhkuowyd7va/exerciseTest.rar Edit 2 It finally works ! Thanks to the answer below. It appears that i needed to change the NewAnswerRow partial line: <input type='text' id='Answers_@(Model.AnswerId)__Answer' name='Answers[@Model.AnswerId].Answer'/> Thanks ! Edit 1: I've followed this guide: http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding/ The funny part is, that when I use his source, it works like it should. But it is almost exactly the

How do I use editortemplates in MVC3 for complex types?

人走茶凉 提交于 2019-12-04 23:35:56
问题 I have two classes, Vat and Product. Product has a property of IVat. I am trying to use editor templates in MVC to display a dropdown list of all the Vat objects when creating/editing a Product. For the dear life of me I cannot get this working. I have the following code which displays the dropdown but it does not set the Vat for the Product when the form gets submitted. Controller: IList<IVatRate> vatRates = SqlDataRepository.VatRates.Data.GetAllResults(); ViewBag.VatRates = new SelectList

Editor Templates for List<string>

对着背影说爱祢 提交于 2019-12-04 09:15:54
I am looking to create a generic editor for some basic models in my ASP.NET MVC3 site. Now they can contain strings, booleans, enums and List collections. What I want to do is extend the default editor templates to recognise List and show a custom editor which can add and remove strings to this list. All the others work just fine. As I cannot name the file List.cshtml of course Is there a way to be able to get this to work? Also why are enums not drop down lists of the enum by default? I know I can create model named templates but I do not know the class names until runtime. Thanks for any

ModelMetadata for complex type in editortemplate in asp.net mvc

强颜欢笑 提交于 2019-12-04 08:05:31
I have a viewmodel that includes a complex property of type TestThing which is declared as: public class TestThing { [Display(Name = "String3", Prompt = "String4")] public string Test1 { get; set; } [Display(Name = "String5", Prompt = "String6")] public string Test2 { get; set; } } I have an EditorTemplate for this type in which I would like to be able to access the meta data for each of the child properties. If the template was for a string for example, I could access the Prompt text by using @ViewData.ModelMetadata.Watermark , but because it is a complex type, I cannot use this method. Is

get value from custom attribute in editor template

≯℡__Kan透↙ 提交于 2019-12-03 12:32:16
问题 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 ? 回答1: In Editor Template you can get the value of custom attribute as below. @model int @{ var CustomAttributes = (ViewData.ModelMetadata).ContainerType.GetProperty(ViewData.ModelMetadata.PropertyName).GetCustomAttributes(typeof(MvcApplication7

ASP.NET MVC 2 - Html.EditorFor a nullable type?

帅比萌擦擦* 提交于 2019-12-03 05:51:22
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 template. The second one also tries to load the decimal template (and fails because it is not a decimal field). The error message is: The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Decimal'. My

Display a byte as a checkbox using a EditorTemplate?

醉酒当歌 提交于 2019-12-02 12:35:37
My model class: public class StatusList { public int StatusID {get;set;} [UIHint("ByteCheckbox")] public byte Active {get;set;} } In /Views/Shared/EditorTemplates I created a file called ByteCheckbox.cshtml The editortemplate ByteCheckbox contains (My 3rd attempt): @model byte @if (Model == 1) { @Html.CheckBox("", true) } else { @Html.CheckBox("", false) } Doing this nicely renders a checkbox. When I change the checkbox status and try to save the changes the model validation complains that the value is 'false' (or 'true') instead of the expected 0 or 1. How to modify the editortemplate to

mvc3, editor template, css clas, maxlength and size

自闭症网瘾萝莉.ら 提交于 2019-12-02 04:05:47
I have an editor template as following but class, maxlength and size attributes are not getting to the source. @using System.Globalization @model DateTime? @Html.TextBox("", (Model != null && Model.HasValue && !Model.Value.ToString(CultureInfo.InvariantCulture).Contains("1900") && !Model.Value.ToString(CultureInfo.InvariantCulture).Contains("0001") ? Model.Value.ToString("MM/dd/yyyy") : string.Empty), new { @class = "datePicker", maxlength = "12", size = "12" }) I have changed it to following and it is still the same @Html.EditorFor(x => x.Criteria.FromDate, new { @class = "datePicker",