razor

How can I pass string value for “asp-for” in asp net 5

我是研究僧i 提交于 2019-12-18 03:38:29
问题 I want to write a Edit.cshtml file for an entity with many properties to edit, so I have to write the following codes many times: <div class="form-group"> <label asp-for="Email" class="col-md-2 control-label"></label> <div class="col-md-10"> <input asp-for="Email" class="form-control" /> <span asp-validation-for="Email" class="text-danger"></span> </div> </div> Actually, there are many entities so that I have to write many Edit.cshtml files. I want to make some simplifications I want to

Why is MVC 4 Razor escaping ampersand when using HTML.Raw in a title attribute

蹲街弑〆低调 提交于 2019-12-18 03:32:12
问题 We recently upgraded to MVC 4 and now we are having titles in our links not display correctly. The problem is before HTML.Raw would not escape & in our title attributes, but now it does. Below is my sample code: <a title="@Html.Raw("Shoe Size 6½-8")">Test</a> Which produces the following markup: <a title="Shoe Size 6&#189;-8">Test</a> The only solution I found so far was to put the entire anchor into a string and then HTML.Raw that string. Why is Html.Raw escaping ampersand in anchor tag in

ASP.net MVC making cell contents as link in Grid.MVC

安稳与你 提交于 2019-12-18 03:27:06
问题 I am developing an ASP.net MVC application. Earlier I used the following code to display a table of products. foreach (var item in Model) { <div class="row"> <div class="cell"> @Html.ActionLink(item.productName, "ViewProduct", "Showcase", new { productID = item.productID }, null) </div> <div class="cell"> @item.quantity </div> <div class="cell"> @item.price </div> </div> } It worked fine, I was able to make the Nx1'st element as a link to redirect to the view that displays the product's

MVC Razor Radio Button

一个人想着一个人 提交于 2019-12-18 03:01:22
问题 In partial view I work with textboxes like this. @model Dictionary<string, string> @Html.TextBox("XYZ", @Model["XYZ"]) How can i generate radiobuttons, and get the desired value in the form collection as YES/NO True/False) ? Currently i am getting null for "ABC" if i select any value for the below. <label>@Html.RadioButton("ABC", @Model["ABC"])Yes</label> <label>@Html.RadioButton("ABC", @Model["ABC"])No</label> Controller public int Create(int Id, Dictionary<string, string> formValues) { /

Cannot perform runtime binding on a null reference, But it is NOT a null reference

元气小坏坏 提交于 2019-12-18 03:00:32
问题 using: MVC 4, ASP.NET Razor I'm getting an error that looks like it shouldn't be possible. It tells me that i'm using a null-reference, States, but clearly it is being set. Controller: public ActionResult Index() { Dictionary<int, string> states = new Dictionary<int, string>() { { -1, "a"}, { 0, "b"}, { 1, "c"}, { 2, "d"}, }; //assigning states ViewBag.States = states; foreach (KeyValuePair<int, string> de in ViewBag.States) { Debug.WriteLine(de.Key); } return View(); } The View: <div class=

How can I set and get the value of a dropdownlist in a grid in Kendo UI MVC?

别等时光非礼了梦想. 提交于 2019-12-18 02:46:48
问题 I'm working with KendoUI MVC in MVC3. I managed to get a dropdown in a grid column. But I have no clue on how to set the selected value, and when I save it doesn't save my selected value. The grid @using Perseus.Areas.Communication.Models @using Perseus.Common.BusinessEntities; <div class="gridWrapper"> @(Html.Kendo().Grid<CommunicationModel>() .Name("grid") .Columns(colums => { colums.Bound(o => o.communication_type_id) .EditorTemplateName("_communicationDropDown") .ClientTemplate("#:

Use Separate js File And use Url Helpers in it with ASP.NEt MVC 3 and Razor View Engine

空扰寡人 提交于 2019-12-18 02:15:30
问题 I ask a similar question here and Darin Dimitrov answer that we can't use Url helper like $.ajax({ url: '@Url.Action("Index")', . . . in separate js file so what is your suggestion to use Url helper in view page and pass it to javascript, I don't want to use hard code url, I need to find it with Url helper.? 回答1: Use a hidden field to store your url, then use javascript to read the hidden field, then use that in your code. That way you can keep the JS file separate to the view. Something like

Calling IEnumerable overload of DisplayNameFor [duplicate]

泄露秘密 提交于 2019-12-18 01:52:51
问题 This question already has answers here : DisplayNameFor() From List<Object> in Model (3 answers) Closed 3 years ago . This works for grabbing the headers( NOT VALUES ): @model IEnumerable<SomeModel> ... <th>@Html.DisplayNameFor(m => m.SomeModelProperty)</th> Which if SomeModelProperty were: [Display(Name = "An Excellent Header")] SomeModelProperty { get; set; } Then it would display "An Excellent Header" in the header th element. You would think this wouldn't work because the model is

ASP.Net MVC 3 Razor: Section Defined But Not Rendered Error

﹥>﹥吖頭↗ 提交于 2019-12-18 01:47:28
问题 I have the following layout template: <div id="columns" class="@View.LayoutClass"> <div id="mainColWrap"> <div id="mainCol"> @RenderBody() </div> </div> @if (View.ShowLeftCol){ <div id="leftCol"> @RenderSection("LeftCol", required: false) </div> } @if (View.ShowRightCol){ <div id="rightCol"> @RenderSection("RightCol", required: false) </div> } </div> If View.ShowLeftCol or View.ShowRightCol are set to false, I get the following error: The following sections have been defined but have not been

What does @: mean in ASP.net MVC Razor?

早过忘川 提交于 2019-12-18 01:42:10
问题 I'm working on an ASP.net MVC Razor view that someone else wrote. I see that it contains the following: <span> @: </span> I know that the @ symbol allows me to insert code into a view, but what does @: stand for? 回答1: In MVC, @ is the respective char that allows you to use razor inside HTML (inside a .cshtml) which in runtime (or precompiled) will be converted to c#. With @ you may write C# within HTML and with @: you may write HTML within C#. Example: @foreach (TestClass item in Model) { @: