简体   繁体   English

当局部视图无效时,从局部视图返回主视图

[英]Returning to the main view from a partial view when the partial view is invalid

My site will have partial views rendered on each page, to provide search functionality. 我的网站将在每个页面上呈现部分视图,以提供搜索功能。

As this is shared on several pages, and all new pages, I don't want to hard code anything or do anything poking around the HTTP Context to determine which master view to render. 由于这是在多个页面以及所有新页面上共享的,因此我不想硬编码任何东西或在HTTP Context上进行任何操作来确定要呈现的主视图。

As such, I have two questions: 因此,我有两个问题:

  1. How do I return to the main view that the partial view was contained in? 如何返回包含部分视图的主视图?
  2. How do I return the partial view model to the main view so that I can correctly show an error message? 如何将部分视图模型返回到主视图,以便可以正确显示错误消息?

Now I realize I can render another full view, like a search results page with a message, but my preference is to have this rendered all in the partial view. 现在,我意识到我可以渲染另一个完整视图,例如带有消息的搜索结果页面,但我的首选是在部分视图中全部渲染。

Thanks in advance. 提前致谢。

Can the form in your partial view use ajax instead of performing a regular POST. 局部视图中的表单可以使用ajax代替常规的POST吗? Then you don't have to worry about where the request came from. 然后,您不必担心请求的来源。

If the ajax post is successful you can redirect the user to the search results page. 如果ajax发布成功,则可以将用户重定向到搜索结果页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM