0

I have my custom route like this

routes.MapRoute(
            name: "child",
            url: "{parcontroller}/{controller}/{action}/{id}",
            defaults: new { id = UrlParameter.Optional },
            constraints: new { }
        );

When i'am in page

http://localhost:1234/Product/Beverage/Browse/10

Is it possible to send "Product" as parcontroller's route value everytime i submit with BeginForm (Not BeginRouteForm) or click on actionlink in this page.

LLF
  • 668
  • 3
  • 10
  • 27
  • What exactly is not working? It is not clear from your question what URL you are POSTing to or what route matches that route. If you post to a URL containing 'Product' in the right place, parcontroller will contain 'Product'. – Rune Sep 17 '14 at 11:26
  • I mean if it's possible to get 'Product' as parcontroller's value when submit just a BeginForm("Delete", "Beverage",...) – LLF Sep 17 '14 at 11:39

1 Answers1

1

Did you check attribute routing?

Defining routes got easier with MVC 5.

[RoutePrefix("Prodcut/{productId}")]
public class ProductController: Controller
{
    [Route("Beverage/Browse/{beverageId}")]
    public ActionResult BrowseBeverage(int productId, int beverageId) { /* ... */ }    
}

your route will now look like this:

http://localhost:1234/Product/1/Beverage/Browse/10

check more here: http://attributerouting.net/

avidenic
  • 653
  • 7
  • 17
  • Sorry, but I still not understand how can this help me. – LLF Sep 17 '14 at 11:40
  • Then please elaborate what are you trying to send and how? Maybe add client side code as well? Also check my edit and tell me if this is what you need? – avidenic Sep 17 '14 at 12:32