If I have View and Partial View, is there a way to transfer data from Partial View to parent?
So, if I have View.cshtml :
<div id="@someDataFromPartialSomehow"> @Html.Partial("_PartialView") </div>
And _PartialView.cshtml :
@{ someDataFromPartialSomehow = "some-data" } <div> Some content </div>
How can I implement something like this?
I tried using ViewBag.SomeDataFromPartialSomehow , but this only leads to null in the parent.
Attempt
To try to get around the generated data problem before the call, I tried this:
View.cshtml :
@{ var result = Html.Partial("_PartialView"); } <div id="@ViewData["Stuff"]"> @result <div>
_PartialView.cshtml :
@{ ViewData["Stuff"] = "foo"; } <div> Content </div>
But calling @ViewDate["Stuff"] doesn't do anything yet.
c # asp.net-mvc razor
dav_i
source share