I want to have two partial views, one for SEARCH
and one for SEARCHRESULTS
.
I want to update SEARCHRESULTS
when the "Search" Button is clicked on the SEARCH
partial view 开发者_开发问答form. SEARCHRESULTS
needs to have the form data fed to it from the SEARCH
partial view.
I'm not totally sure how to go about this. Can I update the SEARCHRESULTS
partial view from my SEARCH
partial view's Controller action?
General Discussion
In the MVC design pattern views are unaware of each other. They may be bound together by the concept of a view assembling multiple partial views but even then the partials are ignorant of each other. This concept is true for ASP.NET MVC. Mike Brind does a good job describing partials and ViewData in his post ASP.NET MVC Partial Views and Strongly Typed Custom ViewModels.
Specific to your Question
To answer your question a partial view can have a link to a controller action that renders a different view, so long as the appropriate information is passed to the controller. How you go about this will depend on what you are trying to do.
Given your question I am going to assume that the SEARCH
partial view is a simple form with a search field and button. While SEARCHRESULTS
is a listing of the returned data. In this instance you'd create a controller action called Search
which takes in a string value and returns just the SEARCHRESULTS
partial or a view containing the SEARCHRESULTS
partial. Scott Guthrie provides a pretty good description of passing data to a view in his blog post Passing ViewData from Controllers to Views.
// returning partial
public ActionResult Search(string q)
{
//do search .......
//.................
return PartialView("SEARCHREULTS", viewdata);
}
精彩评论