asp.net-mvc-routing

ASP.NET MVC Routing not Working in Virtual Directory

淺唱寂寞╮ 提交于 2019-12-12 16:35:55
问题 I have an asp.net mvc 2 app (using .net 4.0) that isn't routing correctly when hosted in a virtual directory. I have the following simple routing rule: routes.MapRoute( "Default", // Route name "{action}", // URL with parameters new { controller = "accounts" } // Parameter defaults ); I'm trying to resolve http://mydomain.com/accounts/new. Where "accounts" is a virtual directory. If I put the app in the root of an IIS website it routes fine for http://mydomain.com/new, but if I put the app in

Parameters dictionary contains a null entry for parameter

六眼飞鱼酱① 提交于 2019-12-12 14:04:57
问题 I am having two view pages using the same controller and model as a way to change the page layout but i am having trouble displaying my second page. This is my error message: The parameters dictionary contains a null entry for parameter id of non-nullable type for method system.web.mvc.actionaresult ListView(int32) in UserController Not sure what is causing the problem i used the same code for the first view page(working) except just changing the view layout. First View <div> <a href="/Roster

How to reference javascript file in ASP.NET MVC 2 Views folder?

Deadly 提交于 2019-12-12 13:15:36
问题 I am trying to accomodate a corporate standard where all page-level javascript is contained in an external file and not included within the ASPX or ASCX file. Using ASP.NET MVC 2, I'm wondering how I can reference the script file (.js) relative to the view. In other words, I don't want to polute my Scripts folder with all of the small .js files that will exist in the application. From an organizational perspective, having the .js file alongside the .aspx/.ascx file makes the most sense. For

asp.net mvc - inconsistent rendering of ActionLink

三世轮回 提交于 2019-12-12 12:50:52
问题 I have a controller which accepts URLs in the following two formats: Network/AddOrEdit -> renders a blank form on a page to add a new network object Network/AddOrEdit/[id] -> renders a page with prepopulated form to edit the network object with ID [id] Obviously it's the same view being used in each instance - one of my design goals is to use the same view for adding and editing purposes. The master page contains a link to the add page like this: @Html.ActionLink("Add", "AddOrEdit", "Network"

How to redirect user based on dropdown selection of master page using session?

不羁的心 提交于 2019-12-12 12:35:54
问题 I have a dropdown on my master page which contains departments list.Now i have several pages which displays list of records based on department selection and change. So when user select new department from dropdown I make an AJAX call to my MVC controller and send department id to that controller and store it in session and used that session across all the pages as because all my pages are department driven. Implementation: @{ int departmentId = 0; int.TryParse(Convert.ToString(Session[

MVC Routing get rid of /Index in URL

不打扰是莪最后的温柔 提交于 2019-12-12 10:59:11
问题 I have a dynamic list of ActionLinks generated at run time like this: @Html.ActionLink(x.Name, "Index", "User", new { x.ID }, null) so I'm hitting the Index method on the User controller. I also have my RouteConfig.cs (it's an MVC4 app) set as follows: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );

ASP.NET MVC 4 Routing I just can't figure out

痴心易碎 提交于 2019-12-12 10:13:34
问题 I'm working on a project in ASP.NET MVC 4 and I'm at a bit of a loss with a particular routing. I have a lot of custom routes already in the project. I am currently making a bunch of controllers for the frontend of the site (publicly visible part) to be able to do thing like abc.com/OurSeoFeatures that gets routed to /OurSeoFeatures/Index Is there any way to do this so that the above would route to something like /frontend/OurSeoFeature and another page would route to /frontend/anotherpage

ASP.NET MVC 3 Case Sensitive URLs

北城以北 提交于 2019-12-12 09:56:27
问题 I am doing a bad thing here. I am asking a question without trying out first by hopping that someone knows an easy way of doing this. Any chance we can make ASP.NET MVC Routing system case sensitive? I would like the following two Urls to be different: example.com/a example.com/A Do we have an easy fix or should write our own handler for this. 回答1: I haven't tried it, but I would think that if you use a regular expression route constraint that only matched the uppercase and lowercase seperate

How to define Html.BeginForm for action with attribute routing?

痴心易碎 提交于 2019-12-12 09:46:41
问题 Controller [HttpGet] [Route("~/search/{clause}/{skip?}")] public async Task<ActionResult> Search(string clause, int skip = 0) { ... } View @using (Html.BeginForm("Index", "search", FormMethod.Get)) { @Html.TextBox("clause", null, new { @class = "form-control col-md-4" }) ... } Rendered Html <form action="/search" method="get"> <input id="clause" name="clause" type="text" value="test"> </form> I am using [HttpGet] partly because i want the search to be accessing via http://myapp.com/search/

ASP.NET MVC 3 Optional Parameter Routing Issue

吃可爱长大的小学妹 提交于 2019-12-12 09:18:57
问题 http://blogs.msdn.com/b/simonince/archive/2011/02/02/asp-net-mvc-3-optional-parameter-routing-issue.aspx The workaround mentioned in the above site is acceptable. But what will happen if the last parameter is not optional and the first two are optional in MVC3?. Can anybody know the workaround. Its just a doubt which is confusing me. 回答1: In an MVC3 route definition, only the last parameter can be optional. As Nat hints at, you can create multiple routes for the same controller action method.