razor

ASP.NET MVC Form and double fields

a 夏天 提交于 2019-12-18 05:48:09
问题 I'm developing an asp.net mvc portal to manage GPS coordinates using localDB. My model is: public class GpsCoordinateViewModel { double Latitute { get; set; } double Longitude { get; set; } } the autogenerated adn related View to create a new GpsCoordinate is: @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <fieldset> <legend>GpsCoordinateViewModel</legend> <div class="editor-label"> @Html.LabelFor(model =>

ASP.NET MVC Form and double fields

ぃ、小莉子 提交于 2019-12-18 05:48:00
问题 I'm developing an asp.net mvc portal to manage GPS coordinates using localDB. My model is: public class GpsCoordinateViewModel { double Latitute { get; set; } double Longitude { get; set; } } the autogenerated adn related View to create a new GpsCoordinate is: @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <fieldset> <legend>GpsCoordinateViewModel</legend> <div class="editor-label"> @Html.LabelFor(model =>

In MVC Razor, how do you do a RenderSection defined below a sub-layout?

点点圈 提交于 2019-12-18 05:42:14
问题 I have a top-level _Layout.cshtml that looks something like this: <html> <head> @RenderSection("Header", required: false) </head> <body> @RenderSection("LeftPane", required: false) @RenderSection("RightPane", required: false) @RenderBody() </body> </html> Then I have two "sub-layouts." One defines just the LeftPane section, the other defines both a LeftPane and a RightPane. These sub-layouts are called _LeftPane.cshtml and _LeftPlusRightPane.cshtml, and they have Layout set to "_Layout.cshtml

In MVC Razor, how do you do a RenderSection defined below a sub-layout?

风流意气都作罢 提交于 2019-12-18 05:42:09
问题 I have a top-level _Layout.cshtml that looks something like this: <html> <head> @RenderSection("Header", required: false) </head> <body> @RenderSection("LeftPane", required: false) @RenderSection("RightPane", required: false) @RenderBody() </body> </html> Then I have two "sub-layouts." One defines just the LeftPane section, the other defines both a LeftPane and a RightPane. These sub-layouts are called _LeftPane.cshtml and _LeftPlusRightPane.cshtml, and they have Layout set to "_Layout.cshtml

Why does Razor not like this?

拟墨画扇 提交于 2019-12-18 05:38:44
问题 Ive got a mega annoying problem I have a view with: @{ if(ViewBag.Section == "Home") { <div id="headerfrontPage"> } else { <div id="header"> } } And I get a compilation error: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup. How do I conditionally write a div? Its for a hack bascially... 回答1: I suspect it is because your divs are not

Why does Razor not like this?

爱⌒轻易说出口 提交于 2019-12-18 05:38:25
问题 Ive got a mega annoying problem I have a view with: @{ if(ViewBag.Section == "Home") { <div id="headerfrontPage"> } else { <div id="header"> } } And I get a compilation error: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup. How do I conditionally write a div? Its for a hack bascially... 回答1: I suspect it is because your divs are not

Lifetime of ViewBag elements in ASP.net MVC3

為{幸葍}努か 提交于 2019-12-18 05:36:24
问题 When will the values of the ViewBag be flushed or cleared ? 回答1: When you leave the view on subsequent request. ViewBag is created in the controller and it will live until the rendering of the view. In addition to this it is something that I would not recommend you using and replace it with view models. 来源: https://stackoverflow.com/questions/6858723/lifetime-of-viewbag-elements-in-asp-net-mvc3

Editing a Variable Length List, ASP.NET MVC 3 Style with Table

£可爱£侵袭症+ 提交于 2019-12-18 05:23:34
问题 I am following Steven Sanderson's blog post here to create an editable and variable length list of items. In his post he uses divs to display a new item in the list but I am using a table. Thus, my partial view for each item is rendering a tr tag with the various fields to edit. Right now my partial view looks something like this: <tr> @using (Html.BeginCollectionItem("LineItems")) { <td> @Html.TextBoxFor(m => m.Description) @Html.ValidationMessageFor(m => m.Description) </td> <td> @Html

Get selected item in DropDownList ASP.NET MVC

喜你入骨 提交于 2019-12-18 05:20:31
问题 I know there are multiple threads on how to get the selected value of a DropDownList. However I can't find the right way to get this value from a partial view in my controller. This is my partial view: @model List<aptest.Models.answer> @Html.DropDownList("dropdownlist", new SelectList(Model, "text", "text")) <button type="submit">next</button> 回答1: In order to get dropdown value, wrap your select list in a form tag. Use models and DropDownListFor helper Razor View @model MyModel @using (Html

Input Tag Helper Not Working with Razor Code

China☆狼群 提交于 2019-12-18 04:47:09
问题 I want to combine an input tag helper with razor code to set an attribute but I cannot get the two technologies to work together. I am simply trying to set the disabled attribute on the input field based on the value of view model property. When i put the razor code after the asp-for tag the razor intellisense is not recognized and the field is not disabled as expected... <input asp-for="OtherDrugs" @((Model.OtherDrugs == null) ? "disabled" : "") class="form-control" /> Rendered output...