razor

@RenderSection in nested razor templates

£可爱£侵袭症+ 提交于 2019-12-18 18:35:33
问题 My problem is I can't seem to use @RenderSection from a nested template when @RenderSection is defined in the base template. Currently, I have a nested base template which is linked to a child template which is then used in the view pages. When I define the @RenderSection in the base template and render it in the view pages it throws an error. Here's the exact problem. I want to create a RenderSection to allow me to insert custom scripts. My base template.... <!DOCTYPE html> <html> <head>

Iterate through collection and print Index and Item in Razor

大憨熊 提交于 2019-12-18 18:09:34
问题 I'm having problems with my razor view. I have the following: public ICollection<Topic> Topics public class Topic { public string Description { get; set; } } I want to iterate through the collection and print out the results like this: @foreach (int index in Enumerable.Range(0, Model.Topics.Count())){ <div>@(index). Model.Topics[@(index)].Description"</div> } The problem is that all I get is: 0. Model.Topics[0].Description" 1. Model.Topics[1].Description" I tried all kinds of things but still

How to get links to URLs in text in ASP.NET MVC 4 with Razor syntax?

南楼画角 提交于 2019-12-18 17:54:54
问题 I have a model with a text field. The text can contain several URLs. It does not have to contain URLs and it does not have a specific format. Using @Html.DisplayFor(model => model.TextWithSomeUrls) the text and the URLs are displayed like normal text of course. I would like to get the URLs displayed as working individual links though. Is there a helper method for this in ASP.NET / Razor? Edit : Right now the output is: http://www.google.com, foo: bar; http://www.yahoo.com Which is exactly the

ExpandoObject, anonymous types and Razor

两盒软妹~` 提交于 2019-12-18 17:35:33
问题 I want to use an ExpandoObject as the viewmodel for a Razor view of type ViewPage<dynamic> . I get an error when I do this ExpandoObject o = new ExpandoObject(); o.stuff = new { Foo = "bar" }; return View(o); what can I do to make this work? 回答1: You can do it with the extension method mentioned in this question: Dynamic Anonymous type in Razor causes RuntimeBinderException So your controller code would look like: dynamic o = new ExpandoObject(); o.Stuff = new { Foo = "Bar" }.ToExpando();

How to display row number in MVC WebGrid

不想你离开。 提交于 2019-12-18 17:30:47
问题 I want to have a column as row number in MVC WebGrid. How can I do it? 回答1: You could use a view model that will contain a property indicating the row number. Let's suppose that you have the following domain model: public class DomainModel { public string Foo { get; set; } } Now you build a view model that will correspond to the requirements of your view: public class MyViewModel { public int RowNumber { get; set; } public string Foo { get; set; } } and then: public ActionResult Index() { //

Request.Browser.IsMobileDevice not working with iPadAir2 and iOS 13.0.1

六月ゝ 毕业季﹏ 提交于 2019-12-18 17:30:10
问题 I am able to detect iPadAir2 device running on iOS 11.4 using Request.Browser.IsMobileDevice and it gives me UserAgent information saying its an iPad: When I do same for iPadAir2 running on iOS 13.0.1 its not giving me iPad keyword anymore: how do I detect its an ipad and ruuning a safari browser? I need this to detect iPad in Razor .chtml page so I can show different Menu for my website. I found this solution from here How to detect device name in Safari on iOS 13 while it doesn't show the

How to save selected DropDownList value in ASP.NET MVC model for POST?

老子叫甜甜 提交于 2019-12-18 17:10:45
问题 I have a property inside my model, like this: public IList<SelectListItem> AllCards { get; set; } Property is being filled with SelectListItem 's by controller with data from database. Also, in my View is @Html.DropDownListFor(m=>m.AllCards,Model.AllCards,"--Select--") . Problem occures during POSTing of a view. That is, onSubmit my Model.AllCards is empty, although there is a value selected inside dropdownlist. I tried adding a new property to the model like this: public SelectListItem

How to populate a @html.dropdownlist mvc helper using JSon

邮差的信 提交于 2019-12-18 16:57:33
问题 I have a <select> which is loaded by a JSon. But I want to use "@html.dropdownlist helper" instead. My Json is: function LoadSites() { $("SelectSite").html(""); $.getJSON("/Pedido/GetSite", null, function (data) { $("#SelectSite").append("<option value=0>Selecione...</option>"); $.each(data.Result, function (index, site) { $("#SelectSite").append("<option value='" + site.Id + "'>" + site.Nome + "</option>"); }); }); this Json populate this... <select id="SelectSite"></select> My Controller:

P3P Header Info in MVC

ぃ、小莉子 提交于 2019-12-18 16:48:14
问题 I'm not sure where I'm suppose to put this in my Asp.net MVC website: HttpContext.Current.Response.AppendHeader("P3P", "CP=\\\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\\\""); I put it in the: public static void RegisterRoutes(RouteCollection routes) { HttpContext.Current.Response.AppendHeader("P3P", "CP=\\\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\\\""); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name

JQuery: Table Row Show/Hide based on Column Value

自作多情 提交于 2019-12-18 16:46:54
问题 I have a table that has a column with Yes/No as possible values <table id="mytable"> <thead> <tr> <th> Col1 </th> <th> Col2 </th> <th> ActiveYN </th> </tr> </thead> <tbody> <tr> <td> Apple </td> <td> 12345 </td> <td> Yes </td> </tr> <tr> <td> Orange </td> <td> 67890 </td> <td> No </td> </tr> <tr> <td> Mango </td> <td> 456745 </td> <td> Yes </td> </tr> I need to show the row if ActiveYN is 'Yes' and Hide id ActiveYN is 'No' How can i access the ActiveYN inside JQuery and show/hide accordingly?