关于MVC的问题求助
最近刚刚接触MVC,自己看着msdn上面的例子自己写了个小程序,然后就遇到了不解的问题。
<ul>
<%foreach (CostList cost in (IEnumerable)ViewData.Model) { %>
<li>
日期:
<%=cost.Date.ToShortDateString() %>
<%if (cost.IsCompleted){%>
-- 花费:
<del><%=cost.Money.ToString() %></del>
已清算
登记人:
<del><%=cost.MainName %></del>
<%} %>
<%else { %>
-- 花费:
<%=cost.Money.ToString() %>
未清算
登记人:
<%=cost.MainName %>
<%} %>
<br />
<a href="/Info/More/<%=cost.CostId.ToString() %>">详细</a>
</li>
<%} %>
</ul>
public class InfoController : Controller
{
private CostViewInfoDataContext cv = new CostViewInfoDataContext();
//
// GET: /Info/
public ActionResult More(int? CostId)
{
var list = from l in cv.CostViewInfo where l.CostId == CostId orderby l.ItemID select l;
return View(list.ToList());
}
}
=》
<a href="/Info/More/?CostId=<%=cost.CostId.ToString() %>">
[解决办法]
其实你这个变成习惯非常不好,自己去拼链接当然某个时候可以,但是如果以后你的Route发生了变化,你这样拼接链接需要改动的地方非常多。
最好是直接用
<%= Html.ActionLink("详细", "More", "Info", new { CostId = cost.CostId }, null })%>