razor

Sending an array of json objects to action with ajax in asp.net mvc 3

被刻印的时光 ゝ 提交于 2019-12-20 11:35:10
问题 I hope anyone can help me (Sorry for my english). I have a problem when I want to send un array of arrays in ajax. My model is: public class SJSonModel { public string Name { get; set; } public bool isChecked { get; set; } } public class SJSonModelList { public List<SJSonModel> Features { get; set; } public List<SJSonModel> MenuItems { get; set; } } The controller: [HttpPost] public ActionResult CheckPreferences(SJSonModelList postData) { BindUserFeatures(postData.Features); return Json(new {

Bind to a Dictionary of Lists of Lists of Bools with a strongly-typed MVC view by using Checkboxes

落爺英雄遲暮 提交于 2019-12-20 11:31:01
问题 I'm using MVC 4, .Net 4, and Visual Studio 2012. I'm trying to use a fairly complex model with one of my views, and I'm having serious trouble getting it to bind properly. The model wraps a Dictionary with integer Keys, and Values that are Lists of Lists of bools. Basically, a search was done on items indicated by the integer, each item had several search terms, and for each of those terms we have a list of results. I display the results on a page, and have a checkbox next to each result. For

Alternative to ViewBag.Title in ASP.NET MVC 3

牧云@^-^@ 提交于 2019-12-20 11:17:09
问题 By default the new project template for ASP.NET MVC 3 adds the following to the default layout (masterpage in razor): <title>@ViewBag.Title</title> The view must then contain the following to assign the title of the page, for instance: @{ ViewBag.Title = "Log On"; } Perhaps it is just my own preference but I find that using the ViewBag to hold the title a little bit wrong (I'm thinking too much magic-string flavor). So my question is: Is this the recommended best practice for people using ASP

ASP.NET MVC3 Partial View naming convention

♀尐吖头ヾ 提交于 2019-12-20 10:59:16
问题 I'm new to the MVC development so please bear with me. Is it really necessary to name my partial view like _Action.cshtml (with the _ underscore) to comply with the naming convention? Here's my problem I have a controller (StudentController) and an action (List) that has a partial view file named "List.cshtml", and have @{ Html.RenderAction("List", "Student"); } to display this inside my HomeController - Index view as partial view which works. But if I name my partial view to _List.cshtml of

ASP.NET MVC3 Partial View naming convention

走远了吗. 提交于 2019-12-20 10:59:05
问题 I'm new to the MVC development so please bear with me. Is it really necessary to name my partial view like _Action.cshtml (with the _ underscore) to comply with the naming convention? Here's my problem I have a controller (StudentController) and an action (List) that has a partial view file named "List.cshtml", and have @{ Html.RenderAction("List", "Student"); } to display this inside my HomeController - Index view as partial view which works. But if I name my partial view to _List.cshtml of

ASP.NET MVC: How to 'model bind' a non html-helper element

落花浮王杯 提交于 2019-12-20 10:43:46
问题 Could you tell me a way(s) that I can bind a model property to a html-element, created without using html helper? In other words to a plain html element such as: <input type="text" /> 回答1: If you are referring to Model Binding, it does not require helpers, but naming convention. Helpers just make it easy and concise to create the HTML markup. You could create plain HTML inputs and just set the name attribute correctly. The default naming convention is just dot based, omitting the parent level

How to layout a page with MVC3 Razor?

三世轮回 提交于 2019-12-20 10:12:17
问题 I've been reading about layouts, sections, views and partial views, but I don't really know how to approach a layout like this example: Top bar: would be like the bar that Facebook have on top. I would contain the authentication information and general options and menus. Navigation bar: would contain information about where are you, and where can you go. Also a "search" box. Body: The actual wanted information. Side bar: would contain relevant information about what is in the body. Footer:

Shared MVC Razor functions in several views

爱⌒轻易说出口 提交于 2019-12-20 09:48:10
问题 I have functions in my view that is shared by several pages: @functions { public HtmlString ModeImage(ModeEnum mode) { switch(mode) { case AMode: new HtmlString("<img etc..."); break; // more etc... } } } Is there a way to have it in a separate file and include it on each page without having to copy and paste it in to each one. I know I can write a .cs file and access it per page, but the function really concerns the view and I'de hate to have to recompile if this function changes. 回答1: This

mvc3 razor conditional wrapper div

匆匆过客 提交于 2019-12-20 09:47:51
问题 What's the best way to handle something like this: Razor Code: @if(!disableRowDiv) { <div class="row"> } <div>some content here</div> @if(!disableRowDiv) { </div> } So that the Razor engine doesn't produce this error : Parser Error Message: The if 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. 回答1: This should work @if(!disableRowDiv) { @:

Make sure all *.cshtml files are set to be “Content” for Build Action

倖福魔咒の 提交于 2019-12-20 09:47:18
问题 A few times when I copy-paste *.cshtml files, Visual Studio for some reason sets Build Action on these files to be "None": This is impossible to detect when you work locally, because the files are present. But when you deploy through WebDeploy, files marked as "None" on Build Action are not packaged. As a result I get non-working application on the server. Question: is there a way to automatically detect such occurrences and prevent? 回答1: You could extend the .csproj with a small snippet that