【发布时间】:2011-02-23 04:11:55
【问题描述】:
我已将以下代码从我的视图移至部分视图并出现错误
我的查看代码是:
函数渲染季节(){ $('#visSeasonbut').click(function() { $('#p2').load(this.href); return false; }); } 函数渲染游戏(){ $('#visGamebut').click(function() { $('#p2').load(this.href); return false; }); } <div id="game">
<%= Html.ActionLink("Game 1", "PitcherTitles", "Test", null, new { id = "visGamebut" })%> </div>
LiveGame.Models.Baseball.Player visPlayer1 = ViewData.Model.GetCurrentTeamPlayer(false); if (visPlayer1 != null) { LiveGame.Models.Baseball.Player rosterPlayer = ViewData.Model.GetTeam(0).RosterDictProp.GetPlayer(visPlayer1.Player_IdProp);
if (ViewData.Model.InningHalfProp == true)
{ %>
show Pitcher Stats here
<%
}
else
{
%>
Show PitchTitles here
<%
}
}
部分视图是这样的:
获胜 损失 时代第二个是:
知识产权 H R 急诊室 BB 所以 人力资源 时代当我点击链接时,我得到错误,“rosterPlayer”未找到,请提出解决方案。谢谢
【问题讨论】:
-
你能把你的代码发布在 action 方法中吗?
-
public ActionResult PitcherStats() { Game currentGame = new Game();返回视图(); } 公共 ActionResult PitchTitles() { 游戏 currentGame = new Game();返回视图(); }
-
请不要在评论中粘贴代码 - 它难以辨认。相反,更新您的问题。此外,由于您没有在
return View()语句中返回模型,因此您的视图没有可使用的模型 - 它是空的,就像错误所说的那样。 -
提示和技巧:使用
<%: %>而不是<%= Html.Encode(...) %>(假设您使用的是asp.net mvc 版本2)。 -
现在我正在使用 MVC 版本 1