3

Below is the code

   [Route("users/{userid}/create")]
   public ActionResult CreateSellerProfile(string userId)
   {
       var country = _locationService.GetCountries().ToDictionary(x => x.Id, x => x.CountryName);
       var model = new SellerProfileViewModel { CountryDic = country };
       model.UserId = userId;
       return View(model);
   }
   [Authorize]

   [HttpPost]

   [Route("users/create")]
   public ActionResult CreateSellerProfile(SellerProfileViewModel model)
   {
     if (!ModelState.IsValid)
       {
           model.StateDic = _locationService.Getstates(model.CountryId).ToDictionary(x => x.Id, x => x.StateName);

           model.CountryDic = _locationService.GetCountries().ToDictionary(x => x.Id, x => x.CountryName);
           return View(model);
       }



       var checkForalreadyExists = _userService.GetSellerProfileByUserId(model.UserId);
       if (checkForalreadyExists == null)
       {
           var domainSellerObj = Mapper.Map<SellerProfileViewModel, SellerProfile>(model);
           _userService.SaveSellerProfile(domainSellerObj);

         return RedirectToAction("CreateSellerProfile", new { model.UserId });

       }
       else
       {
           SetMessage(MessageType.Danger, MessageConstant.GetMessage(Messages.SellerProfileAdded));

     return RedirectToAction("CreateSellerProfile", new { model.UserId });

       }
   }

I want to ask that after we do POST to this action CreateSellerProfile, then we want to redirect again to the same action CreateSellerProfile empty page, we are facing the problem that it's not able to find the route that we defined i.e [Route("users/{userid}/create")]

http://pastebin.com/WU7XS3Vs

user158978
  • 41
  • 4
  • 1
    Possible duplicate of [How to redirect to route using custom attribute routing in MVC5](http://stackoverflow.com/questions/29022582/how-to-redirect-to-route-using-custom-attribute-routing-in-mvc5) – Daniel J.G. Feb 05 '16 at 08:37

1 Answers1

0

You need to specify the parameter name (userId) in the anonymous object:

return RedirectToAction("CreateSellerProfile", new { userId = model.UserId });
haim770
  • 48,394
  • 7
  • 105
  • 133
  • 2
    This method did not work, i tried but showed the same error. Finally solved by using RedirectToRoute() in action and instead of action, i used route name to solve this issue. – user158978 Feb 05 '16 at 12:43