razor

MVC 4 ActionLink Dictionary htmlAttributes doesn't work

主宰稳场 提交于 2019-12-22 05:07:34
问题 I hope this is just a bug but figured maybe it was just me. @Html.ActionLink("Test", "Test", "Test", new { id = 1 }, new Dictionary<string, object> { { "class", "ui-btn-test" }, { "data-icon", "gear" } }) This does work but if I wanted to add further attributes I have to do it manually! @Html.ActionLink("Test", "Test", "Test", new { id = 1 }, new { @class="ui-btn-test", data_icon="gear", data_new_attr="someextra" }) The first doesn't work anymore and I need this one to work. The second works

MVC3 RenderPartial caching across multiple pages

我是研究僧i 提交于 2019-12-22 04:47:07
问题 Can anyone tell me if its possible to Cache a RenderPartial across multiple pages? I have a RenderPartial for a user profile that shouldn't really ever change unless the user updates their profile. So i dont really want to go back and get his/her profile every time i load a page. I would much rather pass the partial around until im forced to update (i.e. profile update) I looked at the DonutHole example that p.haack put together, but it seems to be relevant for a single page. Can someone

MVC3 RenderPartial caching across multiple pages

早过忘川 提交于 2019-12-22 04:47:04
问题 Can anyone tell me if its possible to Cache a RenderPartial across multiple pages? I have a RenderPartial for a user profile that shouldn't really ever change unless the user updates their profile. So i dont really want to go back and get his/her profile every time i load a page. I would much rather pass the partial around until im forced to update (i.e. profile update) I looked at the DonutHole example that p.haack put together, but it seems to be relevant for a single page. Can someone

ASP.NET MVC area namespace problem

三世轮回 提交于 2019-12-22 04:37:30
问题 I create a new area in my asp.net mvc 3 solution named admin . Visual studio automatically assign the names space: MyApp.areas.admin.controllers I change this to MyApp.admin.controllers But it stops resolving the action. Any help in this regard will be appreciated. Thanks 回答1: You need to specify the new namespace when registering the route for your admin area. In your \Areas\admin\adminAreaRegistration.cs file, you need to modify the RegisterArea() method as follows: public override void

MVC 4 razor Data Annotations ReadOnly

戏子无情 提交于 2019-12-22 04:28:10
问题 The ReadOnly attribute does not seem to be in MVC 4. The Editable(false) attribute does not work the way I would want it to. Is there something similar that works? If not then how can I make my own ReadOnly attribute that would work like this: public class aModel { [ReadOnly(true)] or just [ReadOnly] string aProperty {get; set;} } so I can put this: @Html.TextBoxFor(x=> x.aProperty) instead of this ( which does work ): @Html.TextBoxFor(x=> x.aProperty , new { @readonly="readonly"}) or this (

Html.GetEnumSelectList - Getting Enum values with spaces

房东的猫 提交于 2019-12-22 04:07:14
问题 I was using asp-items="@Html.GetEnumSelectList(typeof(Salary))" in my Razor view with a select tag, to populate the list values based on the enum Salary . However, my enum contains some items which I would like to have spaces within. E.g. one of the items is PaidMonthly , but when I display this using Html.GetEnumSelectList , I would like it to be displayed as "Paid Monthly" (with a space in it) I tried using the Description attribute over each member in the enum, however when the select box

MVC Razor - Default Value as Current date for textbox type date

偶尔善良 提交于 2019-12-22 03:42:56
问题 I have a Textbox with type as date . I am trying to set default value of the textbox to current date. @Html.TextBoxFor(x => x.Date, new { @id = "Date", @type = "date", @value = DateTime.Now.ToShortDateString() }) The above line doesn't set default value. How to set default value as current date? 回答1: As Stephen Muecke said, you need to set the property's value on the model. // in controller method that returns the view. MyModel model = new MyModel(); model.Date = DateTime.Today; return View

RenderPartial from different folder in RAZOR

吃可爱长大的小学妹 提交于 2019-12-22 03:23:37
问题 I've been trying to convert my aspx pages to cshtml and having an issue with rendering partial pages from another folder. What I used to do: <% Html.RenderPartial("~/Views/Inquiry/InquiryList.ascx", Model.InquiryList.OrderBy("InquiryId", MvcContrib.Sorting.SortDirection.Descending));%> I would think that the equivalent would be: @Html.RenderPartial("~/Views/Inquiry/_InquiryList.cshtml", Model.InquiryList.OrderBy("InquiryId", MvcContrib.Sorting.SortDirection.Descending)) This is obviously not

How to pass in a lambda to a Razor helper method?

允我心安 提交于 2019-12-22 02:43:50
问题 I have a razor helper method that needs to take in a Func<> that will return some HTML content to print out. This is what I originally had: @helper node(string title, Func<HelperResult> descriptions) { .... <div>@descriptions()</div> .... } @node("title", new Func<HelperResult>(() => { return new HelperResult( @<text> <span>"desc1"</span> <span>"desc2"</span> </text>); })) Unfortunately with this my text never gets printed out. No error either. So I learned about inline helpers, and changed

How to pass in a lambda to a Razor helper method?

不问归期 提交于 2019-12-22 02:42:22
问题 I have a razor helper method that needs to take in a Func<> that will return some HTML content to print out. This is what I originally had: @helper node(string title, Func<HelperResult> descriptions) { .... <div>@descriptions()</div> .... } @node("title", new Func<HelperResult>(() => { return new HelperResult( @<text> <span>"desc1"</span> <span>"desc2"</span> </text>); })) Unfortunately with this my text never gets printed out. No error either. So I learned about inline helpers, and changed