If i have an mvc view content page and i have some data displayed and i want to add more data to this same view page when another actionresult occurs, how do i do this? for instance i have a page with a few details, when a link is clicked i want to go fetch
more data and display it on this same view not another view....how do i do this? thanks
If I understand you right, you have simply add additional nullable parameter for your action (for example name it "expand"). Or provide default value through Routers. Then in this action method check value of it. If it parameter provided, load necessary
data and put it into ViewData. In your page check ViewData for this values, if it not null, then render more data on your page. else just do nothing.
I've try to take about basic principle. Solution can be more elegance if you need.
I hope it helps :)
Marked as answer by sophie86 on Sep 14, 2008 11:01 AM
May be not more elegance.. But I'll describe more detailed.
If I need something similar I'll create MVC Web User Control (ExtendedDetails.ascx). Then create ViewData class for corresponded Controller. Initialize it as I write earlier. In View Page call HtmlRenderPartial("ExtendedDetails", ViewData.Model.ExtendedInfo),
where ExtendedInfo is a Property of ViewData class for containing additional information. In ExtendedDetails.ascx just chech ViewData.Model for null and render if it provided. In another case you can write link for extended page or what are you need by logic
of your application.
sophie86
Member
53 Points
336 Posts
create a view dynamically
Sep 13, 2008 09:06 PM|LINK
Hi,
If i have an mvc view content page and i have some data displayed and i want to add more data to this same view page when another actionresult occurs, how do i do this? for instance i have a page with a few details, when a link is clicked i want to go fetch more data and display it on this same view not another view....how do i do this? thanks
Tolik
Member
34 Points
9 Posts
Re: create a view dynamically
Sep 13, 2008 11:00 PM|LINK
Hi,
If I understand you right, you have simply add additional nullable parameter for your action (for example name it "expand"). Or provide default value through Routers. Then in this action method check value of it. If it parameter provided, load necessary data and put it into ViewData. In your page check ViewData for this values, if it not null, then render more data on your page. else just do nothing.
I've try to take about basic principle. Solution can be more elegance if you need.
I hope it helps :)
sophie86
Member
53 Points
336 Posts
Re: create a view dynamically
Sep 14, 2008 11:01 AM|LINK
thank you...it works :) but, just out of curiousity, what is the more elegant solution?
Tolik
Member
34 Points
9 Posts
Re: create a view dynamically
Sep 14, 2008 12:45 PM|LINK
May be not more elegance.. But I'll describe more detailed.
If I need something similar I'll create MVC Web User Control (ExtendedDetails.ascx). Then create ViewData class for corresponded Controller. Initialize it as I write earlier. In View Page call HtmlRenderPartial("ExtendedDetails", ViewData.Model.ExtendedInfo), where ExtendedInfo is a Property of ViewData class for containing additional information. In ExtendedDetails.ascx just chech ViewData.Model for null and render if it provided. In another case you can write link for extended page or what are you need by logic of your application.