【发布时间】:2020-06-10 19:57:41
【问题描述】:
我又加了一个帖子,这次更正了,因为上一个比较难理解
我有一个页面,其中显示的目录类似于网络驱动器
这是使用目录渲染视图的主要操作:
public ActionResult Index(int? id)
{
return View(_context.NodeEntities.Where(x=>x.ParentId == id));
}
这个动作渲染视图:
@model IEnumerable<Tree.Models.Node>
@{
ViewBag.Title = "Home Page";
}
<div class="container">
<div class="row">
@foreach (var node in Model)
{
<div class="col-md-3 one-node mx-3" id="@node.Id" onClick="Select(this.id)">
<img src="https://img.icons8.com/color/144/000000/folder-invoices.png">
@Html.ActionLink(node.Name, "Index", "Home", new { node.Id }, new { @style = "display:block;" })
</div>
}
</div>
<!-- Button trigger modal -->
<button id="change_name" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
Change name
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Change name:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div id="modalBodyId" class="modal-body">
@Html.Action("EditName", "Home", new { id = 1 })
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<script>
var div;
function Select(clicked_id) {
if (div != null) {
div.style.removeProperty('background-color');
}
div = document.getElementById(clicked_id);
div.style.backgroundColor = "lightgreen";
}
</script>
我想做一些事情,当用户单击给定文件夹时,会显示重命名选项。单击更改名称后,将出现一个弹出窗口,用户可以在其中更改所选文件夹的名称。我写的关于它的内容已经完成,但还没有完全完成。对我来说,它的工作原理是当您单击更改名称时,会出现一个弹出窗口并在“modal-body”中启动@HtmlAction:
public PartialViewResult EditName(int id)
{
Node node = _context.NodeEntities.FirstOrDefault(x => x.Id == id);
return PartialView("_EditName", node);
}
这是部分视图:
@model Tree.Models.Node
@using (Html.BeginForm("ZmienNazwe", "Home"))
{
<div class="form-group">
@Html.TextBoxFor(m => m.Name)
</div>
}
它有效,但我传入了@Html.Action 参数“id = 3”,我想将所选文件夹的 id 放在那里
【问题讨论】:
-
您不能为此使用
@Html.Action,因为剃须刀代码是从服务器执行的 -
我是这么想的,但是我该怎么做呢?
标签: c# html asp.net asp.net-mvc-4