asp.net-mvc-templates

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");

Editing and saving complex objects

允我心安 提交于 2019-12-04 23:05:34
问题 Say you have the following object: public class Address { public String Line1 { get; set; } public String Line2 { get; set; } public String City { get; set; } public String State { get; set; } public String ZipCode { get; set; } public Address() { } } public class Contact { public String FirstName { get; set; } public String LastName { get; set; } public String Telephone { get; set; } public Address BillingAddress { get; set; } public List<Address> ShippingAddresses { get; set; } public

Formatting currency using display template in MVC

为君一笑 提交于 2019-12-04 03:30:38
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"); <span class="currency">@Model.ToString("C", formatProvider)</span> } In my website I have a helper class

Editing and saving complex objects

廉价感情. 提交于 2019-12-03 13:13:24
Say you have the following object: public class Address { public String Line1 { get; set; } public String Line2 { get; set; } public String City { get; set; } public String State { get; set; } public String ZipCode { get; set; } public Address() { } } public class Contact { public String FirstName { get; set; } public String LastName { get; set; } public String Telephone { get; set; } public Address BillingAddress { get; set; } public List<Address> ShippingAddresses { get; set; } public Contact() { // Assume anything that _could_ be null wouldn't be. I'm excluding // most "typical" error

ASP.NET MVC 3 Razor Templates VS RenderPartial

谁说胖子不能爱 提交于 2019-12-03 02:22:09
问题 I just read this blog post on Razor Templating in ASP.NET MVC 3. Put simply, i just dont get it! That is, i don't see why we need this (fairly) complicated code to achieve what can be done IMO easier (and neater) with @RenderPartial ? Here's what i don't like: The template is stored as a Func<T,HelperResult> delegate? That template delegate is persisted in the Controller ViewData (e.g HttpContext.Current.Items) The only "benefit" i read from that blog is that a seperate file isn't required

ASP.NET MVC 3 Razor Templates VS RenderPartial

假装没事ソ 提交于 2019-12-02 15:53:41
I just read this blog post on Razor Templating in ASP.NET MVC 3. Put simply, i just dont get it! That is, i don't see why we need this (fairly) complicated code to achieve what can be done IMO easier (and neater) with @RenderPartial ? Here's what i don't like: The template is stored as a Func<T,HelperResult> delegate? That template delegate is persisted in the Controller ViewData (e.g HttpContext.Current.Items) The only "benefit" i read from that blog is that a seperate file isn't required for templating, meaning you don't need to re-compile etc. But i don't see that as a valid argument. Extra

MVC template from folder other than default (EditorTemplates/DisplayTemplates)?

醉酒当歌 提交于 2019-11-28 19:06:54
Can you point MVC to a folder other than the default ones (Views/Shared/EditorTemplates & Views/Shared/DisplayTemplates)? I'd like to either put them in subfolders below those, or in other folders outside the Shared folder. For example, if I have an editor template under this folder: ~\Views\Order\ProductModel.cshtml How can I tell my EditorFor template to use this tempalte name? I tried fully qualifying it, but this doesn't work: @Html.EditorFor(m => m.ProductModel, @"~\Views\Order\ProductModel.cshtml") I've tried using forward slashes & backslashes, with/without .chstml, every combination I

How to produce non-sequential prefix collection indices with MVC HTML Editor templates?

别等时光非礼了梦想. 提交于 2019-11-28 12:52:59
The following code has been stripped down a lot, but basically what I'm looking to achieve is as follows: I'd like to able to edit Questions and their containing Answer Choices, while being able to dynamically add/remove Questions/Answer Choices from the page. Ideally, the HtmlFieldPrefix for my items would be non-sequential, but Html.EditorFor() uses a sequential index. I have a Question ViewModel that contains an IEnumerable of Answer Choices: public class QuestionViewModel { public int QuestionId { get; set; } public IEnumerable<AnswerChoiceViewModel> AnswerChoices { get; set; } } In my

MVC template from folder other than default (EditorTemplates/DisplayTemplates)?

被刻印的时光 ゝ 提交于 2019-11-27 11:54:57
问题 Can you point MVC to a folder other than the default ones (Views/Shared/EditorTemplates & Views/Shared/DisplayTemplates)? I'd like to either put them in subfolders below those, or in other folders outside the Shared folder. For example, if I have an editor template under this folder: ~\Views\Order\ProductModel.cshtml How can I tell my EditorFor template to use this tempalte name? I tried fully qualifying it, but this doesn't work: @Html.EditorFor(m => m.ProductModel, @"~\Views\Order

How to produce non-sequential prefix collection indices with MVC HTML Editor templates?

耗尽温柔 提交于 2019-11-27 07:17:45
问题 The following code has been stripped down a lot, but basically what I'm looking to achieve is as follows: I'd like to able to edit Questions and their containing Answer Choices, while being able to dynamically add/remove Questions/Answer Choices from the page. Ideally, the HtmlFieldPrefix for my items would be non-sequential, but Html.EditorFor() uses a sequential index. I have a Question ViewModel that contains an IEnumerable of Answer Choices: public class QuestionViewModel { public int