开发者

partial view error

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 开发者_StackOverflow社区 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


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); 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜