Pass ViewData to RenderPartial

bruce
bruce
24 Points
12 Posts

Hi,

I am using partial view. I want render partial view in master page using Html.RenderPartial.

How to pass viewdata.

Views: 8114
Total Answered: 1
Total Marked As Answer: 0
Posted On: 16-Sep-2015 05:11

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Moderator
1170 Points
210 Posts
     

Hi bruce,

Try following code in View page (where the partial view called) as:

ASPX View:

<divid="AddSampleForm"style="display: none;">
<%Html.RenderPartial("AddSample", newViewDataDictionary { { "ProductID", ProductID.ToString() }, { "ProductName", ProductName.ToString() } }); %>
</div>
 

Razor View:

<divid="AddSampleForm"style="display: none;">
@Html.RenderPartial("AddSample", newViewDataDictionary { { "ProductID", ProductID.ToString() }, { "ProductName", ProductName.ToString() } })
</div>
 

Use ViewData in Partial view as:

AZPX View:

<div class="FeedbackformHeading">
Sample Requeste For : <%=ViewData["ProductName"]%>
</div>

Razor View:

<div class="FeedbackformHeading">
Sample Requeste For : @ViewData["ProductName"]
</div>
Posted On: 06-Nov-2015 02:14
banner

Blog

Active User (0)

No Active User!
 Log In to Chat