ASP.Net MVC Redirect To A Different View

后端 未结 5 965
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 04:02

Is it possible to redirect to a different view from a controller?

For example, all my controllers inherit from a custom controller that has a constructor that I wan

5条回答
  •  醉话见心
    2020-12-05 04:27

    I am not 100% sure what the conditions are for this, but for me the above didn't work directly, thought it got close. I think it was because I needed "id" for my view by in the model it was called "ObjectID".

    I had a model with a variety of pieces of information. I just needed the id.

    Before the above I created a new System.Web.Routing.RouteValueDictionary object and added the needed id.

    (System.Web.Routing.)RouteValueDictionary RouteInfo = new RouteValueDictionary();
    RouteInfo.Add("id", ObjectID);
    return RedirectToAction("details", RouteInfo);
    

    (Note: the MVC project in question I didn't create, so I don't know where all the right "fiddly" bits are.)

提交回复
热议问题