Jquery ASP.NET MVC:在div中显示值
我使用jquery post调用一个操作方法:Jquery ASP.NET MVC:在div中显示值,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我使用jquery post调用一个操作方法: $('#selector').click(function (event) { var jqxhr = $.post("/MyController/MyAction", $("form").serialize(), function (data) { $('#myDIV').html(data); //ok here // Missing code, display text from my mod
$('#selector').click(function (event) {
var jqxhr = $.post("/MyController/MyAction", $("form").serialize(),
function (data) {
$('#myDIV').html(data); //ok here
// Missing code, display text from my model in another div
});
});
在缺少代码时,我会编写代码以在另一个div中显示模型中的文本
有什么想法吗
谢谢,如果我没弄错的话。从ajax调用中接收的数据不包含要重新传递到的模型数据。我建议您扩展ajax调用的答案,也许可以使用JSon答案。 差不多
{ { myValue="<p>my html data</p>"} , {myValue = Model.CustomerID.ToString() }}
如果数据在模型中,请创建隐藏字段以保存数据:
@Html.HiddenFor(x => x.DataInModel)
然后从中获取数据:
$('#selector').click(function (event) {
var jqxhr = $.post("/MyController/MyAction", $("form").serialize(),
function (data) {
$('#myDIV').html(data); //ok here
// Missing code, display text from my model in another div
$('#AnotherDiv').html($('#DataInModel').val())
});
});
不要误解你的要求:为什么你不能像第一季那样做呢?MyDiv mymodel看起来怎么样?您是将mymodel传递到主视图还是部分视图?@3nigma这是一个部分视图,我要刷新的div不在该部分视图中是的,我知道您要刷新的div不在部分视图中,但我想问的是,如果您在局部视图?
$('#selector').click(function (event) {
var jqxhr = $.post("/MyController/MyAction", $("form").serialize(),
function (data) {
$('#myDIV').html(data); //ok here
// Missing code, display text from my model in another div
$('#AnotherDiv').html($('#DataInModel').val())
});
});