-1

I can change the method name but can anyone tell me why this doesn't work? How can i make it working without changing method name. Also I don't want to specify the action name in the view. Is it possible?

        [HttpGet]
        [Route("AddUpdateCategories/{storeId}")]
        public ActionResult AddUpdateStoreCategories(int storeId)
        {

            return View();
        }

        [HttpPost]
        public ActionResult AddUpdateStoreCategories(int StoreId,int[] ShopCategoryId)
        {

            return null;
        }

Problem is post action is not getting called on submit.

Marko
  • 12,543
  • 10
  • 48
  • 58
Mir Gulam Sarwar
  • 2,588
  • 2
  • 25
  • 39

1 Answers1

0

You don't have to change the method name. The problem is that this post action has no route. If you use attribute routing, you have to specify a route for each action. Both of these actions would end up with the same route attribute, but the [HttpPost] attribute is enough for the routing framework to work out which one to use.

[Route("AddUpdateCategories/{storeId}")]
public ActionResult AddUpdateStoreCategories(int storeId)
{
    return View();
}

[HttpPost]
[Route("AddUpdateCategories/{storeId}")]
public ActionResult AddUpdateStoreCategories(int StoreId,int[] ShopCategoryId)
{
    return null;
}
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • yes,I know adding [Route("AddUpdateCategories/{storeId}")] in the post action will work.But this looks I am passing only storeId in the method which is not correct. Do you have any clarification? Or m I missing something? – Mir Gulam Sarwar Mar 26 '15 at 15:20
  • No, the route is *not* the same as the method definition. The inclusion of `storeId` in the route merely means that will be the source of that particular parameter. You can still have other parameters, and none of them have to be in the route. – Chris Pratt Mar 26 '15 at 15:22
  • Thank u very much. I was having much problem to understand attribute routing. Sometimes get mislead. – Mir Gulam Sarwar Mar 26 '15 at 15:27