Reputation: 473
I am currently facing an issue about adding dynamic partial view into a partial view which is pre-rendered.
Situation: I have a view which contains a partial view (contains nothing initially, lets call it "A"). I want to add a dynamic partial view called "B" into the partial view "A" and keep stacking over time, and each of the partial view "B" would have their own GUID.
Possible to achieve this scenario?
Upvotes: 0
Views: 170
Reputation: 26940
You can add partial views with ajax:
Controller "MyController":
public ActionResult GetPartial()
{
var identifier = Guid.NewGuid();
return PartialView("_MyPartial", identifier);
}
JS:
function addPartial(){
$('<div></div>')
.load('@Url.Action("GetPartial", "MyController")')
.appendTo('#container');
}
First partial view:
<div id="container"></div>
<input type="button" value="add" id="btnAdd" />
JS:
$('#btnAdd').click(addPartial);
Upvotes: 1