asp.net mvc 动态显示不同的部分视图

时间:2023-03-09 16:12:58
asp.net mvc 动态显示不同的部分视图

首先是AJAX请求

  //第一次打开 默认s单行文本
$.ajax({
type: "GET",
url: "/Admin/Field/ChoiceType4Edit",
data: { fieldtype: "@Html.ValueFor(m => m.Type)", fieldid: "@Html.ValueFor(m => m.ID)" },
dataType: "html",//格式是html
success: function (evt) {
$('#rescontent').html(evt);//替换成新的数据
}
});

先时代位置 就是在

<tbody id="rescontent"></tbody>

在控制器里面

        public PartialViewResult ChoiceType(string fieldtype)
{
FieldInfo info = new FieldInfo();
return PartialView(string.Format(@"~/Skin/Sky/Admin/Field/_{0}.cshtml", fieldtype), info);
}

好咯 大功告成