Har*_*ock 4 javascript asp.net-mvc
当我单击按钮时,我希望将“ View_Name”的新副本添加到页面中。我将如何在javascipt中执行此操作?以下是页面的开头。
<fieldset>
<legend>Some Form</legend>
@{ Html.RenderPartial("Partiale"); }
<input type="button" value="Add new Item" />
</fieldset
Run Code Online (Sandbox Code Playgroud)
见下面的例子
HTML:
<fieldset>
<legend>Some Form</legend>
<div id="divPartial">
</div>
<input type="button" id="mybutton" value="Add new Item" />
</fieldset>
Run Code Online (Sandbox Code Playgroud)
jQuery:
<script src="//ajax.googleapis.com/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>
Run Code Online (Sandbox Code Playgroud)
控制器动作:
public ActionResult FilteredItemGallery()
{
return PartialView("GalleryPartial");//return your partial view here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4781 次 |
| 最近记录: |