我有一个部分视图,我在哪里提交:
cell.clipsToBounds = NO;
控制器功能:
<input type="image" src="~/Resources/Images/DoSomething.png" border="0" alt="Submit" value="DoSomething" name="DoSomething"/>
在函数DoSomething()中,我想操作myModel并将其发送回视图。
但我有一个问题:
调用DoSomething后,只显示部分视图,没有样式。
如何在不丢失其他部分视图和样式的情况下更新部分视图?
答案 0 :(得分:0)
您可以使用$.ajax
执行此操作,将onclick="someJsFunction()"
添加到按钮和
someJsFunction(e)
{
e.preventDefault();
//do the ajax hit here to your action method
//and on the success event of ajax append the partial view html to the //corresponding div where you want to show the partial content
//and don't forget to set the datatype:html in ajax parameters
}
答案 1 :(得分:0)
您必须使用以下代码来获取部分视图的返回结果
<input type="image" src="~/Resources/Images/DoSomething.png" border="0" id="SubmitBtn" alt="Submit" value="DoSomething" name="DoSomething"/>
您必须添加&#34; PartialResultDivName &#34;划分您的视图并在该div中显示返回数据。检查下面的代码。
$("#SubmitBtn").click(function () {
$.ajax(
{
url: '@Url.Action("DoSomething", "ControllerName")',
type: "Post",
async: false,
dataType: "html",
contentType: "application/json;charset=utf-8",
data: $('form').serialize(), //here you have to pass your form name for pass all data to controller action
contentType: "application/json;charset=utf-8",
success: function (data) {
$('#PartialResultDivName').html(data);
}
});
});
&#13;