asp.net-mvc-routing

Ignoring a route in ASP.NET MVC

混江龙づ霸主 提交于 2019-12-05 00:01:44
I am just learning to work with routing in ASP.NET MVC and am trying to understand the IgnoreRoute method. I am trying to prevent users from accessing "Content/{filename}.html" . I have placed this as the first call in my RegisterRoutes method. Here is my code: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("Content/{filename}.html"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new { controller = "^.*", action = "

What's the WebApi [FromUri] equivalent in ASP.NET MVC?

笑着哭i 提交于 2019-12-04 23:59:28
In WebApi I can decorate a parameter on a controller action with [FromUri] to have the components of the URI 'deserialized', if you will, into a POCO model; aka model-binding. Despite using MVC since 2.0, I've never used it for websites (dunno why). What's the equivalent of it in ASP.NET MVC 5? The attribute doesn't seem to be recognised in the IDE unless I need to reference a library. I'd like ~/thing/2014/9 to bind to the model below: public class WhateverModel { public int Year { get; set; } public int Month { get; set; } } Thanks Update In the other question (link above), the OP says:

Restful MVC Web Api Inheritance

混江龙づ霸主 提交于 2019-12-04 23:45:33
问题 Im building myself an asp.net mvc 4 web api I've been through the Microsoft videos and I think they are good. Http Verbs are used. Resources are nouns, it's dandy with repositories, etc. But one thing really bugs me I'm under the impression that this GET http://www.myurl.com/api/sellers/{id}/products is restful and GET http://www.myurl.com/api/products?$filter = sellerID eq {id} is not. All I see in what I've read about the new web api is the former latter. Is there native support for the

Unexpected route chosen while generating an outgoing url

天涯浪子 提交于 2019-12-04 23:40:47
Please, consider the following routes: routes.MapRoute( "route1", "{controller}/{month}-{year}/{action}/{user}" ); routes.MapRoute( "route2", "{controller}/{month}-{year}/{action}" ); And the following tests: TEST 1 [TestMethod] public void Test1() { RouteCollection routes = new RouteCollection(); MvcApplication.RegisterRoutes(routes); RequestContext context = new RequestContext(CreateHttpContext(), new RouteData()); DateTime now = DateTime.Now; string result; context.RouteData.Values.Add("controller", "Home"); context.RouteData.Values.Add("action", "Index"); context.RouteData.Values.Add("user

controller path not found for static images? asp.net mvc routing issue?

試著忘記壹切 提交于 2019-12-04 23:30:23
I have an image folder stored at ~/Content/Images/ I am loading these images via <img src="/Content/Images/Image.png" /> Recently, the images aren't loading and I am getting the following errors in my error log. What's weird is that some images load fine, while others do not load. Anyone have any idea what is wrong with my routes? Am I missing an ignore route for the /Content/ folder? I am also getting the same error for favicon.ico and a bunch of other image files... <Fatal> -- 3/25/2010 2:32:38 AM -- System.Web.HttpException: The controller for path '/Content/Images/box_bottom.png' could not

Can you pass a model with RedirectToAction?

二次信任 提交于 2019-12-04 23:13:16
I'm using mvc 2 release candidate, and am wondering if there's any way to pass a model to an action using RedirectToAction. For example, I have an edit action which takes an ID, and loads the record from a database, displays the current values in text boxes and lets the user edit and click submit: public ActionResult Edit(int ID) Then I have an edit action for the HttpPost which takes a model and updates the database: [HttpPost] public ActionResult Edit(Administration.Models.ManagementCompanyModel model) Because I already have the model containing the new data, I don't want to simply re-direct

how may i add integer list to route

限于喜欢 提交于 2019-12-04 22:00:19
问题 I'm trying to add int[] array to my Url.Action something like this: var routeData = new RouteValueDictionary(); for (int i = 0; i < Model.GroupsId.Length; i++) { routeData.Add("GroupsId[" + i + "]", Model.GroupsId[i]); } in my view: Url.Action("Index", routeData) but in html I'm getting: GroupsId%5B0%5D=1213&GroupsId%5B0%5D=1214 and not: GroupsId=1213&GroupsId=1214 I need it because I have a checkbox list, and when I do post I'm binding groupIds to int[] and then pass to view where I have

Built in method to encode ampersands in urls returned from Url.Action?

断了今生、忘了曾经 提交于 2019-12-04 21:59:09
问题 I am using Url.Action to generate a URL with two query parameters on a site that has a doctype of XHTML strict. Url.Action("ActionName", "ControllerName", new { paramA="1" paramB="2" }) generates: /ControllerName/ActionName/?paramA=1&paramB=2 but I need it to generate the url with the ampersand escaped: /ControllerName/ActionName/?paramA=1&paramB=2 The fact that Url.Action is returning the URL with the ampersand not escaped breaks my HTML validation. My current solution is to just manually

ASP.NET MVC 3 routing

孤街浪徒 提交于 2019-12-04 20:20:00
i am trying to create route. Which is /emlak/TITLE/number.aspx such as /emlak/Here_is_your_best_property/123456.aspx Global.asax: routes.MapRoute( "Product", "{controller}/{deli}/{productId}", new { controller = "emlak", action = "Index" }, new { productId = UrlParameter.Optional , deli = UrlParameter.Optional } ); My controller namespace emrex.Controllers { public class EmlakController : Controller { // // GET: /Emlak/ public ActionResult Index(String productId, String deli) { return View(); } } } and i am getting next error: Server Error in '/' Application. The resource cannot be found.

ASP.NET MVC 3 Optional Parameter Routing Issue

眉间皱痕 提交于 2019-12-04 19:37:00
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. 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. If you want to have one required parameter and 2 optional parameters, you can define multiple routes: ..