(已编辑)现在我已经修复了以前的错误,但得到了错误:
路径中的非法字符。
我正在尝试遍历一些 json 构建无序列的链接列表。我@for
在显示模板和Html.DisplayFor
视图中有声明。这是我的代码:
控制器:
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace app.Web.Areas.Admin.Controllers
{
public class CommonReportsController : Controller
{
public ActionResult CommonReports(Guid orgId)
{
JObject TopListData = JObject.Parse(System.IO.File.ReadAllText(@"C:\Dev\app\app.Web\json\TopListData.json"));
string cData = Newtonsoft.Json.JsonConvert.SerializeObject(TopListData);
var TopListDataView = TopListData;
return View(TopListDataView);
}
}
}
看法:
@model app.API.Models.CommonReports.CommonReportsModel
@using app.API.Resources;
@using app.Web.Utility;
@{
ViewBag.Title = Text.Get(Text.eTextType.Label, @Text.Get(Text.eTextType.Label, "CommonReports_Title"));
}
@section BreadCrumbTitle {
@( Text.Get(Text.eTextType.Tab, @Text.Get(Text.eTextType.Label, "CommonReports_Title")))
}
<div class="titletop">@ViewBag.Title</div>
<div id="CommonReportsList">
@Html.DisplayFor(m => m.CommonReports, "CommonReportsDisplayTemplate")
</div>
显示模板:
@model app.API.Models.CommonReports.CommonReportsModel
@using app.API.Resources;
<ul class="row-centered-list">
@for (var i = 0; i < 1; i++)
{
<li><img src="~/Images/document.png" /> @Html.ActionLink(@Text.Get(Text.eTextType.Label, TopListDataView[i].ListLabel), TopListDataView[i].ListView, TopListDataView[i].ListController, null, new { data_toggle = "tooltip", data_original_title = TopListDataView[i].ListToolTip })<span class="newRed"> - @Text.Get(Text.eTextType.Label, "CommonReports_New")</span></li>
}
</ul><br />
模型:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Web.Mvc;
namespace InRollPlus.API.Models.CommonReports
{
public class CommonReportsModel
{
public class TopListData
{
public string ListLabel
{
get;
set;
}
public string ListView
{
get;
set;
}
public string ListController
{
get;
set;
}
public string ListToolTip
{
get;
set;
}
}
[UIHint("CommonReportsDisplayTemplate")]
public string CommonReports
{
get;
set;
}
public string TopListView
{
get;
set;
}
public IList<TopListData> TopListDataView
{
get;
set;
}
}
}
我在这里做错了什么?