简体   繁体   中英

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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