部分视图错误

发布于 2024-10-18 09:45:05 字数 3123 浏览 0 评论 0原文

我已将以下代码从我的视图移至部分视图并收到错误

我的视图代码是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵情客 2024-10-25 09:45:05

当您渲染此部分时,请确保您正在传递一个模型:

<% Html.RenderPartial("SomePartialName", Model); %>

当然,不要忘记将您的部分强类型化到模型中:

<%@ Control 
    Language="C#" 
    Inherits="System.Web.Mvc.ViewUserControl<AppName.Models.SomeModelType>" 
%>

此外,从您发布的评论来看,您似乎没有将任何模型传递到您的视图。因此,请更改此设置并确保传递模型,否则您将无法使用 Model 属性:

public ActionResult PitcherStats() 
{ 
    Game currentGame = new Game(); 
    return View(currentGame); 
} 

public ActionResult PitchTitles() 
{ 
    Game currentGame = new Game(); 
    return View(currentGame); 
} 

When you render this partial make sure you are passing a model:

<% Html.RenderPartial("SomePartialName", Model); %>

And of course don't forget to strongly type your partial to the model:

<%@ Control 
    Language="C#" 
    Inherits="System.Web.Mvc.ViewUserControl<AppName.Models.SomeModelType>" 
%>

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:

public ActionResult PitcherStats() 
{ 
    Game currentGame = new Game(); 
    return View(currentGame); 
} 

public ActionResult PitchTitles() 
{ 
    Game currentGame = new Game(); 
    return View(currentGame); 
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文