asp.net-mvc-routing

MVC route where path exists

别说谁变了你拦得住时间么 提交于 2019-12-04 18:55:16
问题 I'm trying to create a route that will caption a url like http://mysite.com/tech/ but I also have an actual directory under the site that is /tech, which contains other static resources. Not my design choice, but I'm migrating an older site to mvc and dont want to break a bunch of very old links. My route seems to keep failing, and what I can figure is that the server sees this directory and is trying to serve up the default file from it... but none is found, and it fails. I'd like it to use

UriPathExtensionMapping in MVC 4

ε祈祈猫儿з 提交于 2019-12-04 18:45:28
How do I use UriPathExtensionMapping in MVC4? I've added the mapping in the formatter such that: MediaTypeMappings.Add(new UriPathExtensionMapping("json", new MediaTypeHeaderValue("application/json")) But I can't use the extension on my route unless I add a verb, such as: routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}.{extension}" ); Then it'll recognize my desired media type, but it also starts expecting "extension" as a parameter on the action. Example: public object Get(string extension) { } Instead of just: public object Get() { } How can I resolve this? Thanks!

What is Routedata.Values[“”]?

好久不见. 提交于 2019-12-04 17:26:31
问题 I am surprised to see that there is no article which answers this question with any details. I have few questions related to RouteData.Values[""] . I saw this code: public ActionResult Index() { ViewBag.Message = string.Format("{0}---{1}--{2}", RouteData.Values["Controller"], RouteData.Values["action"], RouteData.Values["id"]); return View(); } Here it is basically reading values which potentially sounds like "Meta-data" of the controller. Or is it something that View can also pass to

Pass List<int> from actionlink to controller method

柔情痞子 提交于 2019-12-04 17:19:24
In my controller I have this: ViewBag.lstIWantToSend= lstApps.Select(x => x.ID).ToList(); // creates a List<int> and is being populated correctly I want to pass that list to another controller.. so in my view I have: @Html.ActionLink(count, "ActionName", new { lstApps = ViewBag.lstIWantToSend }, null) Method in Controller: public ActionResult ActionName(List<int> lstApps) // lstApps is always null Is there a way to send a list of ints as a route value to a controller method? its not possible directly but you can do it with Json if i have List<int> ViewBag.lstIWantToSend= new List<int> {1, 2, 3

Custom Routing Rules (e.g. www.app.com/project/35/search/89/edit/89)

梦想与她 提交于 2019-12-04 16:17:31
I would like to create routing rules like the following: www.app.com/project/35/search/89/edit/48 ---> action is edit in the project controller The passed variables should be project# (35), search# (89), and edit#(48) Can someone help me structure a routes.MapRout() for this. I want to use: routes.MapRoute( "Default", "{controller}/{projectid}/search/{searchid}/{action}/{actionid}", new { controller = "Home", action = "Edit", projectid = "", actionid = "" } ); But from previous experience, this type of MapRoute will fail... I've only gotten something in the following format to work:

ASP.NET Web API RTM and subdomain routes

≡放荡痞女 提交于 2019-12-04 14:33:53
问题 I am having issues getting Web API to work with subdomain-based routes. In short, I am getting to the right controller and method but the data token out of the subdomain is not being picked up by WebAPI. I have this in my scenario: contoso.myapp.com fabrikam.myapp.com {tenant}.myapp.com All resolving to the same ApiController and I want to be able to extract the {tenant} token. I used the code in this article http://blog.maartenballiauw.be/post/2012/06/18/Domain-based-routing-with-ASPNET-Web

Setting up ASP.Net MVC 4 Routing with custom segment variables

回眸只為那壹抹淺笑 提交于 2019-12-04 13:46:20
问题 I just began working on an application with a couple areas (basic grid master / details type system..) I'm looking into taking advantage of the nice routing features in MVC (4 specifically) and I'm "just not getting it" I presume. Currently the only route defined is the basic one: routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Account", action = "Index", id = UrlParameter.Optional } ); which is fine, it works with the areas we have defined, so I'm assuming it

ASP.NET MVC 3: Moved app into virtual directory. What do I have to change?

半城伤御伤魂 提交于 2019-12-04 11:52:10
问题 Folks, I have been working on an MVC 3 app. I was using VS 2010's built-in web server. Today, for various reasons, I was asked to move it into a virtual directory and run it under IIS 7, still on my development PC. Now that its URL is "localhost/MyVirtualDirectory" as opposed to "localhost:12345", what do I need to change to make routing work, and where? I'm not using any raw HTML anchor tags or redirects, just @Html.ActionLink and so on. According to what I've read, if I've been doing things

URL Redirection in ASP.NET MVC

╄→尐↘猪︶ㄣ 提交于 2019-12-04 11:35:54
I was working on a Website which was earlier built with ASP.NET Web Forms and now is built with ASP.NET MVC. We made the new MVC version live last week. But the old login url which is www.website.com/login.aspx has been bookmarked by many users and they still use that and hence they get 404 errors. So I was wondering which would be the easiest and best way to redirect the user from the old url to the new mvc url which is www.website.com/account/login Like this login url, I am expecting the users may have bookmarked few other urls also, so what will be the best way to handle this ? You could

Returning a view with it's model from an ActionFilterAttribute

耗尽温柔 提交于 2019-12-04 10:41:23
When implementing error-handling using the built-in validation-helpers on a strongly-typed view, you usually create a try/catch block within the controller and return a view with it's corresponding model as a parameter to the View() method: The controller public class MessageController : Controller { [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Models.Entities.Message message) { try { // Insert model into database var dc = new DataContext(); dc.Messages.InsertOnSubmit(message); dc.SubmitChanges(); return RedirectToAction("List"); } catch { /* If insert fails, return a view with it