When I click the button I want a new copy of the "View_Name" to be added to the page. How would I do this in javascipt? Below is what the page looks like to start with.
<fieldset>
<legend>Some Form</legend>
@{ Html.RenderPartial("Partiale"); }
<input type="button" value="Add new Item" />
</fieldset
When I click the button I want a new copy of the "View_Name" to be added to the page. How would I do this in javascipt? Below is what the page looks like to start with.
<fieldset>
<legend>Some Form</legend>
@{ Html.RenderPartial("Partiale"); }
<input type="button" value="Add new Item" />
</fieldset
Share
Improve this question
asked Jul 30, 2013 at 0:39
user751651user751651
3
- You would load the view using ajax. – Jasen Commented Jul 30, 2013 at 1:03
- Can you post your Model and your Controller Action? – ataravati Commented Jul 30, 2013 at 3:15
- The controller is only returning the view a above and there is no model right now. The view is only html right now – user751651 Commented Jul 30, 2013 at 3:17
1 Answer
Reset to default 5See below example
HTML:
<fieldset>
<legend>Some Form</legend>
<div id="divPartial">
</div>
<input type="button" id="mybutton" value="Add new Item" />
</fieldset>
Jquery:
<script src="//ajax.googleapis./ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#mybutton").click(function () {
var url = "/Item/FilteredItemGallery/";
$.ajax({
url: url,
cache: false,
type: "POST",
success: function (data) {
$('#divPartial').html(data);
/* little fade in effect */
$('#divPartial').fadeIn('fast');
},
error: function (reponse) {
alert("error : " + reponse);
}
});
});
});
</script>
Controller Action:
public ActionResult FilteredItemGallery()
{
return PartialView("GalleryPartial");//return your partial view here
}