Display a view from another controller in ASP.NET MVC

后端 未结 7 1201
孤街浪徒
孤街浪徒 2020-11-29 16:06

Is it possible to display a view from another controller?

Say for example I have a CategoriesController and a Category/NotFound.aspx view.

7条回答
  •  甜味超标
    2020-11-29 16:16

    Yes, you can. Return an Action like this :

    return RedirectToAction("View", "Name of Controller");
    

    An example:

    return RedirectToAction("Details/" + id.ToString(), "FullTimeEmployees");
    

    This approach will call the GET method

    Also you could pass values to action like this:

    return RedirectToAction("Details/" + id.ToString(), "FullTimeEmployees", new {id = id.ToString(), viewtype = "extended" });
    

提交回复
热议问题