阅读背景:

如何在ASP MVC5中的同一操作上定义属性路由后重定向到操作

来源:互联网 

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 });

       }
   }
   [Route("users/{



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: