前台代码:
<iframe style="display:none;" name="gg"></iframe>
<form action="/demo/add" method="post" target="gg">
<table class="info_form table table-striped">
<tr>
<td>姓名</td>
<td><input name="name" /></td>
</tr>
<tr>
<td>年龄</td>
<td><input name="age" /></td>
</tr>
<tr>
<td>颜值</td>
<td><input name="yz" /></td>
</tr>
</table>
<button class="btn btn-default" type="submit">确定</button>
</form><script>function call_back(){ alert("睡你妈逼,起来嗨!");}</script>注意:form的target属性。设置为iframe的name属性值。这样的话后台返回的view会显示在iframe中
后台代码:
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(my m)
{
testEntities t = new testEntities();
t.my.Add(m);
t.SaveChanges();
return Content("<script>parent.call_back();</script>");
}
这样页面不会刷新。也可以调js方法。。。。不想用ajax的话。用这个也是不错的选择
来源:https://www.cnblogs.com/gaocong/p/4766132.html