我有几个实体,这些实体都实现了With sheets(youractionsheet).Range(“A2:AB” & sheets(youractionsheet).cells(rows.count,3).end(xlup).row)
Set myaction = .cells.find(what:=“No Action”)
If not myaction is nothing then
Do until myaction is nothing
myaction.font.italic = true
myaction.font.color = 8421504
Set myaction = .findnext(myaction)
Loop
End if
End with
接口(在现实世界中,我有10个实体)。
IEntity
我正在显示每个实体的列表(在表中),并且我想显示一种模式形式来编辑实体的名称,而无需重复代码。
所以我有一个局部视图来显示列表,还有一个按钮来启动模态表单:
public interface IEntity
{
short Id { get; set; }
string Name { get; set; }
}
public partial class Part: IEntity { }
public partial class Localization : IEntity { }
现在,模态形式也是局部视图(在此简化):
@model IEnumerable<IEntity>
@foreach (IEntity item in Model)
{
<tr>
<td>
@Html.DisplayFor(m => item.Name)
</td>
<td>
<button data-id="@item.Id" onclick="editEntity(this)">
<i class="fa fa-edit text-primary"></i>
</button>
</td>
</tr>
}
//Here the modal container part
<div class="modal fade" id="editModal" aria-hidden="true">
<div id="editModalContainer">
</div>
</div>
这时,我正在通过ajax渲染模态:
@using (Html.BeginForm())
{
@Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" })
@Html.TextBoxFor(m => m.Name)
<button type="submit" id="submitEdit" class="btn btn-primary">Enregistrer</button>
}
,控制器的方法是:
function editEntity(clickedEntity) {
//I need the type of entity to get right modal title and so on
var type = $(clickedEntity).closest("div").attr('data-entityType');
var entityId = $(clickedEntity).attr('data-id');
$.ajax({
type: "GET",
url: "/Defaults/GetEntityModal",
data: { id: entityId, entityType: type },
success: function (response) {
$("#editModalContainer").html(response);
$("#editModal").modal('show');
},
failure: function (response) {
alert("failure");
},
error: function (response) {
alert("error");
}
});
但是在下一步进行模态模型的服务器端验证时,我会遇到很多麻烦。
所以我的问题是,在那种情况下,这是呈现模式的正确方法还是我必须为表中的每个条目制作一个表格?
答案 0 :(得分:0)
这是正确的方法,但是模态视图必须先呈现,然后才能由ajax更新:
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-hidden="true">
<div id="editModalContainer">
@{Html.RenderPartial("_ModifyEntityModal", Model.EditEntityModalView);}
</div>
</div>