我想在ajax按钮点击后在主视图中更新我的局部视图。我单步浏览局部视图,模型具有正确的值。我将值存储在html中,以便它们显示在主视图中。不显示新值。我想知道是否有人可以帮助我。
查看型号:
fn perform_if_exists<F, R>(item: u8, vector: &mut Vec<u8>, func: F)
where F: Fn(&mut Vec<u8>, usize) -> R
{
let idx = vector.iter().position(|i| *i == item );
if let Some(i) = idx {
func(vector, i);
}
}
fn main() {
let mut v = vec![1, 2, 3];
perform_if_exists(1, &mut v, Vec::remove);
println!("{:?}", v);
}
控制器:
namespace myApp.ViewModels
{
public class mrfResult
{
public string mrf { get; set; }
public string round { get; set; }
public string route { get; set; }
public string supplier { get; set; }
public string status { get; set; }
public string deadline { get; set; }
}
}
部分视图:
[HttpPost]
public ActionResult RFInfo(RfInfo pRfInfo)
{
List<mrfResult> newResult = new List<mrfResult>();
.....
mrfResult nRow = new mrfResult();
nRow.mrf = pRfRow; nRow.round = pRfInfo.round; nRow.route = routeRow.ServiceId.ToString();nRow.supplier = supRow.name; nRow.status = statName; nRow.deadline = supRow.deadline.ToString();
newResult.Add(nRow);
.....
return PartialView("~/Views/RFMaster/_Partials/_GetRFDetails.cshtml", newResult);
}
主要观点:
@model List<myApp.ViewModels.mrfResult>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@section scripts {
<script src="~/Javascript/RFInfo.js"></script>
}
<div>
@{
string routeName = "(a - b)";
string servId = "";
if (Model != null) {
for (var i = 0; i < Model.Count; i++)
{
servId = Model[i].supplier;
break;
}
}
}
<span>@routeName</span><br />
<span>@servId</span><br />
<span>@routeName</span><br />
</div>
Jquery:
@model List<myApp.ViewModels.mrfResult>
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/Scripts/multi-select/multiple-select.js"></script>
<link href="~/Scripts/multi-select/multiple-select.css" rel="stylesheet" />
<link href="~/CSS/css_RFInfo.css" rel="stylesheet" />
@section scripts {
<script src="~/Javascript/RFInfo.js"></script>
}
@{
int cnt = 0;
}
<body>
<div>
<h1>RF Information</h1>
............
<div class="contRfDetails">
@Html.Partial("~/Views/RFMaster/_Partials/_GetRFDetails.cshtml")
</div>
</div>
</body>
在主视图中首次加载具有局部视图的div时显示:
(a - b)
(a - b)
这是正确的。
按下'btnFind'按钮后,控制器httppost动作结果功能被触发。根据jquery参数填充模型。然后将模型发送到局部视图。在局部视图中对模型执行循环。检索其中一个值(sup1)并存储在变量'servId'中。然后在跨度'@servId中指定该变量。
主视图中的div现在应如下所示:
(a - b)
SUP1
(a - b)
但我回来的只是视图中的原始数据。
(a - b)
(a - b)
答案 0 :(得分:0)
js应该使用控制器中的数据更新html元素。 从以下位置更新脚本行:
*success: function (data) {
alert('Process Successful');
},*
到
success: function (data) {
$('.contRfDetails').html(data);
},