开发者

Action-View binding: magic!

开发者 https://www.devze.com 2022-12-17 12:24 出处:网络
Say there\'s HomeController with an Details-action. return View() will send data to the Detals.aspx in the Home folder. But who makes that binding? and what if I want it to go to Edit.aspx instead?

Say there's HomeController with an Details-action. return View() will send data to the Detals.aspx in the Home folder. But who makes that binding? and what if I want it to go to Edit.aspx instead?

Background: Alot of the code in Details.aspx and Edit.aspx is identical, save for开发者_开发百科 one textbox. Maybe by MVC rigor, the view is not supposed to make that kind of decisions, but hey, there's got to be a limit.


You can make it go to Edit.aspx by specifying it as a parameter of the View() function.

return View("Edit");

As to who makes the actual binding happen, it's the View Engine. It receives the returned ViewResult and analyzes it to see which template file to load and display. When it gets the string "Edit", it runs a find routine, using the context of the controller, to search a number of directories for filenames that match the convention. It starts in the controller's View directory, and then searches the Shared directory.


If you want to Edit.aspx to be rendered you could return View("Edit");

0

精彩评论

暂无评论...
验证码 换一张
取 消