Redirect to Action by parameter mvc

后端 未结 4 1150
说谎
说谎 2021-02-13 02:58

I want to redirect to an action in other Controller but it doesn\'t work here\'s my code in ProductManagerController:

[HttpPost]
public ActionResult RedirectToIm         


        
4条回答
  •  佛祖请我去吃肉
    2021-02-13 03:27

    This should work!

    [HttpPost]
    public ActionResult RedirectToImages(int id)
    {
        return RedirectToAction("Index", "ProductImageManeger", new  { id = id });
    }
    
    [HttpGet]
    public ViewResult Index(int id)
    {
        return View(_db.ProductImages.Where(rs => rs.ProductId == id).ToList());
    }
    

    Notice that you don't have to pass the name of view if you are returning the same view as implemented by the action.

    Your view should inherit the model as this:

    @model 
    

    You can then access your model in view as:

    @Model.
    

提交回复
热议问题