部分视图错误
我已将以下代码从我的视图移至部分视图并收到错误
我的视图代码是:
function renderSeason() { $('#visSeasonbut').click(function() { $('#p2').load(this.href); return false; }); } function renderGame() { $('#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
<%
}
}
部分视图如下所示:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
Wins Losses ERA第二个是:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
IP H R ER BB SO HR ERA当我单击链接时,出现错误,找不到“rosterPlayer”,请提出解决方案。谢谢
I have moved following code from my view to partial view and getting error
My view code is:
function renderSeason() {
$('#visSeasonbut').click(function() { $('#p2').load(this.href); return false; });
}
function renderGame() {
$('#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
<%
}
}
and partial views are like this :
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
Wins
Losses
ERA
second one is :
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
IP
H
R
ER
BB
SO
HR
ERA
When I click links, I get error , "rosterPlayer" not found, Please suggest solution. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您渲染此部分时,请确保您正在传递一个模型:
当然,不要忘记将您的部分强类型化到模型中:
此外,从您发布的评论来看,您似乎没有将任何模型传递到您的视图。因此,请更改此设置并确保传递模型,否则您将无法使用 Model 属性:
When you render this partial make sure you are passing a model:
And of course don't forget to strongly type your partial to the model:
Also from the comment you posted it looks like you aren't passing any model to your views. So change this and ensure a model is passed or you cannot use the Model property: