razor

Accessing nested JSON elements in MVC and Razor

徘徊边缘 提交于 2021-01-28 06:53:46
问题 I'm very new to MVC, JSON, Razor and indeed .Net - so go easy on me. I have been working through the CosmosDB demo from Microsoft with no problems. I then started using the code as a base to retrieve nested JSON elements into a HTML table. I have managed to do this successfully for the first level of nested elements but have struggled with the second level. This a sample JSON document. { "title": "War Diary for 2nd Battalion Scots Guards September 1943", "date": "September 1943", "unit": "2nd

MVC Html.DisplayFor for Lists of Derived Models

我的梦境 提交于 2021-01-28 05:31:37
问题 Let's assume that I have three classes: Derived1ViewModel , Derived2ViewModel and BaseViewModel which serves as a superclass for the Derived1ViewModel and Derived2ViewModel . I have a DisplayTemplate which has as a model a List<BaseViewModel> and I would like to call this template from views which are using as a model a List<Derived1ViewModel> or a List< Derived2ViewModel> . If I try to do this, an exception is triggered saying that it cannot convert a List<Derived1ViewModel> or List

How to check if a RadioButton is checked in Razor?

a 夏天 提交于 2021-01-28 04:03:11
问题 I have the following lines of code in a cshtml file, <div class="YesNo"> <label><input type="radio" name="YesNo_@pNum" value="Yes" />@yesLabel</label> <label><input type="radio" name="YesNo_@pNum" value="No" checked />@noLabel</label> </div> How can I use an if condition in Razor to check if "Yes" radiobutton is checked and then only display a certain label? I have these 2 properties in my model, public string YesLabel { get { return COff.YesLabel ?? "Yes"; } } public string NoLabel { get {

RouteValueDictionary to HtmlAttributes

微笑、不失礼 提交于 2021-01-28 04:00:54
问题 I know I can add html attributes to my tag by doing something like: var htmlAttributes = new RouteValueDictionary { { "data-foo", "bar" } }; var tag = new TagBuilder("div"); tag.MergeAttributes(htmlAttributes ); @tag Output: <div data-foo="bar"></div> I wonder if I can add attributes in a similar way by using markup instead of a tag builder. Maybe something like: var htmlAttributes = new RouteValueDictionary { { "data-foo", "bar" } }; <div @htmlAttributes.ToHtmlAttributes() ></div> Expected

RouteValueDictionary to HtmlAttributes

时光毁灭记忆、已成空白 提交于 2021-01-28 03:43:50
问题 I know I can add html attributes to my tag by doing something like: var htmlAttributes = new RouteValueDictionary { { "data-foo", "bar" } }; var tag = new TagBuilder("div"); tag.MergeAttributes(htmlAttributes ); @tag Output: <div data-foo="bar"></div> I wonder if I can add attributes in a similar way by using markup instead of a tag builder. Maybe something like: var htmlAttributes = new RouteValueDictionary { { "data-foo", "bar" } }; <div @htmlAttributes.ToHtmlAttributes() ></div> Expected

Use One Identity for WebAPI and Asp.Net Core In different projects

六月ゝ 毕业季﹏ 提交于 2021-01-28 03:25:49
问题 I have a solution that contains 2 dot net core projects : Web API Web Application(MVC) The web application is a web API consumer. My web application controller will use httpclient for getting data and I use razor for the client (no Javascript library such as Angular). I want to use Microsoft identity for authentication and recently I have read about JWT . In which project should I add Microsoft Identity? (Because we need authentication for building a token in JWT ) If I must add it in the Web

Blazor /Pages folder required for all pages/views?

蹲街弑〆低调 提交于 2021-01-28 01:08:47
问题 Using the default Blazor helloworl app, i copied the FetchData.razor page to a separate, custom folder. The result: The page is not being rendered properly (the page is taking up the whole screen / the navigation menu is gone). Question: Do blazor pages/views must be in the /Pages folder? 回答1: You are free to put components in whatever folders you wish, the Pages folder is just what comes with the template. But you will notice in the default templates, the Pages folder has a file called

Mixing Razor and Javascript: Assigning a number from Model to a Javascript variable in a view

一个人想着一个人 提交于 2021-01-28 01:04:46
问题 I'm having difficulties to assign just a basic number from Model to a Javascript variable via Razor. All that I came up with was the code below, which works, but is rather ugly as I have to convert the string value into a number. Is there any other way to just get it right away in the numeric format without any conversions? var MyNumber = parseInt('@Model.MyNumber'); 回答1: You should be able to do this: var MyNumber = @Model.MyNumber; or better, use the brackets to make the Razor part explicit

Seperate js File utf-8 not working in ASP.NET MVC Razor

扶醉桌前 提交于 2021-01-27 14:52:05
问题 I have a textBox. When I click mybtn if myTxtBox is empty a tooltip appears and give the message which attached to 'data-original-title'. It's working fine but when I add turkish charachters inside text instead of "Some text", these charachters are shown as a question mark. $("#mybtn").on('click', function (e) { if ($("#myTxtBox").val() == "") { MyTooltipCreator("#myTxtBox"); $("#myTxtBox") .attr('data-original-title', "Some text") .tooltip('fixTitle') .tooltip('show'); } }); The strange

relative path in stylesheets within asp.net mvc areas

[亡魂溺海] 提交于 2021-01-27 05:06:24
问题 I have a project with the current structure My Project /Content /Controller /View /Model /Areas /Area1 /View /Controller /Model /Area2 /View /Controller /Model All of the area views are using a root shared _Layout view which is referencing a css file under the root content directory. The css file under the content folder is referencing images or other content with the same directory like below: .box-shadow { -webkit-box-shadow: 0px 5px 80px #505050; -moz-box-shadow: 0px 5px 80px #505050; box