Partial view update from another partial view - ASP.NET MVC2

I want to have two partial views , one for SEARCH and one for SEARCHRESULTS .

I want to update SEARCHRESULTS when the "Search" button is pressed in the partial SEARCH view form. SEARCHRESULTS must have form data submitted to it from a partial representation of SEARCH .

I'm not quite sure how to do this. Can I update a partial SEARCHRESULTS view from my Controller <action? T>?

+6
c # asp.net-mvc asp.net-mvc-2 partial-views
source share
1 answer

General discussion
In design patterns, MVCs do not know about each other. They can be connected together by the concept of a representation that collects several partial representations, but even then partial ones do not know about each other. This concept is true for ASP.NET MVC. Mike Brind describes Partial and ViewData well in his post Partial ASP.NET MVC views and strongly typed custom view models .

Specific to your question
To answer your question, a partial view may have a link to the action of the controller, which displays a different view if the relevant information is passed to the controller. How you do this will depend on what you are trying to do.

Given your question, I'm going to suggest that the partial view of SEARCH is a simple form with a search field and a button. So far, SEARCHRESULTS is a list of returned data. In this case, you will create an action with the SEARCH controller that takes a string value and returns only a partial SEARCHRESULTS expression or a view containing a partial SEARCHRESULTS expression. Scott Guthrie gives a pretty good description of data transfer in the form of his blog post Transfer ViewData from controllers to Views .

 // returning partial public ActionResult Search(string q) { //do search ....... //................. return PartialView("SEARCHREULTS", viewdata); } 
+8
source share

All Articles