razor

asp.net mvc 3 handleerror global filter always shows IIS status 500 page

萝らか妹 提交于 2019-12-17 19:48:45
问题 I have tried everything, even uninstalling asp.net mvc3, and I can't get HandleError global filter working. I have set up the HandleError filter in the Global.asax: public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } Also I have CustomErrors enabled (it does not matter if i set defaultRedirect="Error" or not, I think that is in the docs because is needed for older versions of mvc): <customErrors mode="On" /> Trying to navigate

What's the base class of a Razor View in ASP.NET MVC3

自古美人都是妖i 提交于 2019-12-17 19:34:22
问题 I'm trying to have all my views inherit from a custom class so that I can add certain behaviour and values to all pages, but I'm having some issues. I tried subclassing System.Web.Mvc.WebViewPage but I'm forced to implement an Execute procedure that I don't know what it should do. Also, if I try to access the Context variable, I get a null reference (really weird). This leads me to think that I may have the wrong base class.... Any thoughts? 回答1: Diego, System.Web.Mvc.WebViewPage is the right

Using javascript regex containing '@' in razor

痴心易碎 提交于 2019-12-17 19:34:07
问题 I am performing email address validation with javascript in a razor view page. The regex I am going to use is similar to the one proposed at Validate email address in JavaScript? However, because the regex contains an '@' character, I am getting parser error when try to run the web app. my regex looks like /^...otherpart @* ... other part$/ I tried to add an '@' character to make the in the origin regex ... @@* ..., this eliminated the compilation error but seems to make the regex stops

Submitting partial view data from parent view

孤人 提交于 2019-12-17 19:28:56
问题 How to submit partial view data from parent view . I am newbie to MVC, I have created a partial view _CurrentData which contains editor controls - textbox etc and added Submit button in the main view: <div class="row"> <div class="col-md-12"> @Html.Partial("_CurrentData", Model.CurrentItemDetails) </div> </div> <div class="row"> <div class="col-md-2 col-md-offset-5"> <div> <input type="button" class="btn btn-primary" value="Submit" id="btnSubmit"/>    <input type="button" class="btn btn

Javascript variable in razor ActionLink

ε祈祈猫儿з 提交于 2019-12-17 19:16:51
问题 var boxIdValue = 233; var result = title + '<br/>@Html.ActionLink("Detail", "Show", "Boxes", new{boxId=233}, null)'; When I hardcode boxId then it works. But when I write: var result = title + '<br/>@Html.ActionLink("Detail", "Show", "Boxes", new{boxId=boxIdValue}, null)'; It doesn't. Is it possible to mix javascript var and razor in this way? 回答1: Have a look at this related Stack Overflow question. The reason why this is a challenge is that the Razor method executes on the web server at

Html.Partial() skips the controller action

别来无恙 提交于 2019-12-17 19:15:43
问题 I am using @Html.Partial("Index") to call upon an action called "Index" in a controller, which should then return me the "Index" view. Unfortunately, it looks like the controller action is ignored because I get an error in Index view that Model is null. I tried setting breakpoints in the controller action and they are simply being skipped, it seems that the view "Index" is rendered without reading the controller? What is going on here? Thx for any ideas. Controller Action code is below:

MVC .NET Model Binding to Array on the fly

烈酒焚心 提交于 2019-12-17 18:58:52
问题 In Scotts blog post he describes how to post an array of objects to the controller. My Question how best to generate a View for this that allows the user to add more array items on the fly? If I write foreach(MyModel item in Model) { <p>@Html.TextBoxFor(m => item.Name)</p> } and have the controller add a new item to the array each time it generates <input type="text" name="item.Name" /> missing the 1 Array index. If I hand code the <input> then it works but I lose all the client side

Post checked checkboxes to controller action without using HTML helper like Html.CheckboxList

怎甘沉沦 提交于 2019-12-17 18:53:18
问题 I have a list of items and I would like to delete items that are checked in a list of checkboxes. I can't use something like CheckboxList since I'm using Grid.Mvc to display my lines. That is why I create checkboxes in each line with column.add("<input type="checkbox".....>); . Every checkbox has its own ID: <input type="checkbox" id="3"> <input type="checkbox" id="4">... I would like to know how to pass all checked checkbox IDs to the controller (from there I will perform delete operations).

How to generate dropdownlist in asp.net MVC razor

你。 提交于 2019-12-17 18:52:36
问题 In my razor I am generating dropdown list like this. @{ var listItems = new List<ListItem> { new ListItem { Text = "Home To School", Value = "0" }, new ListItem { Text = "School To Home", Value = "1" } }; } @Html.DropDownList("Direction", new SelectList(listItems),new {onchange = "getAlldata()"}) HTML generated from this is like this <select id="Direction" name="Direction" onchange="getAlldata()"> <option>Home To School</option> <option>School To Home</option> </select> but I want to generate

Bind WebGrid form AJAX

血红的双手。 提交于 2019-12-17 18:48:11
问题 I'm a newbie to MVC3 and Razor and I need help on binding/loading a WebGrid once data is returned from AJAX post. Any help would really be appreciated (project due date quickly approaching) ;) My scenario is this: I have two cascading drop down lists. The first list contains the regions from the database. Once a region is selected it populates the second drop down with a list of facilities. Once a facility is selected I need to populate a WebGrid with a list of buildings. I have the cascading