一段时间后,我正在重新访问MVC,但现在我遇到了一些奇怪的错误,但我似乎无法解决这些错误。
@Model List<StockEdgeTest.Models.Department>
@using StockEdgeTest.Models
@{
ViewBag.Title = "Department List";
}
<div style="font-family:'Agency FB'">
<h2>Department List</h2>
<ul>
@foreach (Department dep in @Model)
{
<li>
@Html.ActionLink(dep.DepartmentName, "Index", "Employee", new { DepartmentID = Convert.ToInt32(dep.DepartmentID) })
</li>
}
</ul>
</div>
该视图给出了o / p
System.Collections.Generic.List`1 [StockEdgeTest.Models.Department]列表部门列表HR财务DB IT管理Corpo银行设施无用董事
我不知道如何删除此行System.Collections.Generic.List`1 [StockEdgeTest.Models.Department]列表
更重要的是,actionlink似乎不起作用,它只是生成https:// localhost:44354 /?Length = 8而不是https:// localhost:44354 / Employee / Index
任何想法如何解决这个问题?编辑:动作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using StockEdgeTest.Models;
namespace StockEdgeTest.Controllers
{
public class DepartmentController : Controller
{
// GET: Department
public ActionResult Index()
{
EmployeeContext ecn = new EmployeeContext();
List<Department> e1 = ecn.Department.ToList();
return View(e1);
}
}
}
修正您的观点:
@model List<StockEdgeTest.Models.Department>
@{
ViewBag.Title = "Department List";
}
<div style="font-family:'Agency FB'">
<h2>Department List</h2>
<ul>
@foreach (Department dep in @Model)
{
<li>
@Html.ActionLink(dep.DepartmentName, "Index", "Employee", new { id = dep.DepartmentID}, null )
</li>
}
</ul>
</di
并在您的索引操作中替换:
return View()
与
[Route("{id?}")]
public ActionResult Index(int id)
{
.....
List<StockEdgeTest.Models.Department> model= ...your code
return view(model);
}
```
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句