asp.net-mvc-routing

The view 'Index' or its master was not found.

戏子无情 提交于 2019-11-29 00:50:07
The view 'Index' or its master was not found. The following locations were searched: ~/Views/ControllerName/Index.aspx ~/Views/ControllerName/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx I got this error when using ASP.Net mvc area. The area controller action are invoked, but it seems to look for the view in the 'base' project views instead of in the area views folder. What you need to do is set a token to your area name: for instance: context.MapRoute( "SomeArea_default", "SomeArea/{controller}/{action}/{id}", new { controller = "SomeController", action = "Index", id =

Dynamic url rewriting with MVC and ASP.Net Core

大兔子大兔子 提交于 2019-11-28 23:46:13
问题 I am re-writing my FragSwapper.com website (currently in Asp 2.0!) with ASP.Net Core and MVC 6 and I'm trying to do something I would normally have to break out a URL Re-Write tool along with db code and some Redirects but I want to know if there is a "better" way to do it in ASP.Net Core possibly with MVC Routing and Redirecting. Here are my scenarios... URL Accessing the site: [root] What to do: Go to the usual [Home] Controller and [Index] View (no [ID]). ...it does this now: app.UseMvc

Trailing slash on an ASP.NET MVC route

左心房为你撑大大i 提交于 2019-11-28 23:19:47
In the latest MVC preview, I'm using this route for a legacy URL: routes.MapRoute( "Legacy-Firefox", // Route name "Firefox-Extension/", // URL with parameters new { controller = "Home", action = "Firefox", id = "" } // Parameter defaults ); The problem is that both of these URL's work: http://example.com/Firefox-Extension http://example.com/Firefox-Extension/ I only want the second to work (for SEO). Also, when I create a link to that page, the routing engine gives me back a URL without a trailing slash. This is the code I'm using to generate the link: <%= Html.ActionLink("Firefox Extension",

How to make IRouteConstraint filter route

安稳与你 提交于 2019-11-28 23:17:25
I wrote a custom route constraint, but its filter just doesn't get recognized. Does anyone have an example working use of IRouteConstraint ? Also, note to developers: I get double display of the form on my android. Something must be wrong with the partial rendering? Here's a simple constraint that looks up an article slug in a fictional repository: public class SlugRouteConstraint : IRouteConstraint { private readonly ISlugRepository slugRepository = new SlugRepository(); public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values,

URL.Action includes id when constructing URL

流过昼夜 提交于 2019-11-28 23:04:25
I'm using ASP.Net MVC. Here's my code snippets from a controller named Course: public ActionResult List(int id) { var viewmodel.ShowUrl = Url.Action("Show", "Course"); ... } public ActionResult Show(int id) { ... } viewmodel.ShowUrl picks up whatever the value is of the "id" parameter. So viewmodel.ShowUrl becomes "/Course/Show/151" (value of id is 151); I want to be able to set the id part on the client based on user interaction. I want the value of viewmodel.ShowUrl to be "/Course/Show". This seems like a bug to me. I'm not telling Url.Action to include an id value. It's doing it on its own.

How to route GET and DELETE requests for the same url to different controller methods

僤鯓⒐⒋嵵緔 提交于 2019-11-28 22:54:15
Here are my routes in Global.asax routes.MapRoute("PizzaGet", "pizza/{pizzaKey}", new { controller = "Pizza", action = "GetPizzaById" }); routes.MapRoute("DeletePizza", "pizza/{pizzaKey}", new { controller = "Pizza", action = "DeletePizza" }); Here are the my controller methods [AcceptVerbs(HttpVerbs.Get)] public ActionResult GetPizzaById(long pizzaKey) [AcceptVerbs(HttpVerbs.Delete)] public ActionResult DeletePizza(long pizzaKey) When I do a GET it returns the object, but when I do a DELETE I get a 404. It seems like this should work, but it doesn't. If I switch the two routes around then I

Make URL language-specific (via routes)

淺唱寂寞╮ 提交于 2019-11-28 20:48:44
Its hard to find an answer to this specific question, so ill pop it up here: We want to build up our urls completely language specific, meaning www.mysite.com/EN www.mysite.com/DE this is done in the RouteConfig with url: "{language}/{controller}/{action}/{id}" But then the tricky part: www.mysite.com/EN/Categories www.mysite.com/DE/Kategorien I.e. make the controllername appear in a multiple languages, but point to the same controller. Is this even possible? Well, this is partially possible (the language part only). The controller name in a different language is definitely an interesting

ASP.net MVC custom route handler/constraint

我怕爱的太早我们不能终老 提交于 2019-11-28 20:46:39
I need to implement an MVC site with urls per below: category1/product/1/wiki category1/product/2/wiki category1/sub-category2/product/3/wiki category1/sub-category2/sub-category3/product/4/wiki etc. etc. where the matching criteria is that the url ends with "wiki". Unfortunately the below catch-all works only in the last part of the url: routes.MapRoute("page1", // Route name "{*path}/wiki", // URL with parameters new { controller = "Wiki", action = "page", version = "" } // Parameter defaults I have not had the time to go through the MVC extensibility options so I was wondering what are the

Plus (+) in MVC Argument causes 404 on IIS 7.0

限于喜欢 提交于 2019-11-28 20:14:54
I have an MVC route that is giving me hell on a staging server running IIS. I am running Visual Studio 2010's development server locally. Here is a sample URL that actually works on my dev box: Root/CPUBoards/Full+Size Results Server Error404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable. Here is the complete behaviour I am seeing. Localhost: Root/CPUBoards/Full Size - Resolves Root/CPUBoards/Full%20Size - Resolves Root/CPUBoards/Full+Size - Resolves Staging Server with IIS 7.0: Root/CPUBoards/Full

Getting full url of any file in ASP.Net MVC

我的未来我决定 提交于 2019-11-28 19:11:45
I want to generate complete Url (with domain name etc) of any file in MVC. Example: A .jpg file or an exe file. Example: If I give "~/images/abc.jpg" it should return " http://www.mywebsite.com/images/abc.jpg " I am aware of the Url.Action overload that takes the protocol as a parameter. But Url.Action can be used only for Actions. I want something like Url.Content function that takes protocol as a parameter. Do you know if any method to get complete url of any file? I have tried: VirtualPathUtility.ToAbsolute , ResolveClientUrl , ResolveUrl but all of these don't seem to work. Adeel You can