Update A Partial View From Another Partial View - ASP.NET MVC2

拈花ヽ惹草 提交于 2019-12-03 14:28:29

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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!