2015-02-11 20 views
14

ja dostaję ten błąd:„System.Web.Mvc.HtmlHelper” ma zastosowanie metody o nazwie „częściowy”

error CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax."}

Z tego co czytałem tutaj Razor View Engine : An expression tree may not contain a dynamic operation jest to, że jest to spowodowane użyciem viewbag (?) z której naprawdę korzystam z sesji.

To jest mój formularz internetowy:

@using SuburbanCustPortal.MiscClasses 

@{ 
    ViewBag.Title = "Account Screen"; 
} 

<h2>AccountScreen</h2> 

<div class="leftdiv"> 
    <fieldset> 
    <legend>Customer Info</legend> 
    @Html.Partial("CustomerInfo") 
    </fieldset> 

    <fieldset> 
    <legend>Delivery Address</legend> 
    @Html.Partial("DeliveryAddress") 
    </fieldset> 

    <fieldset> 
    <legend>Delivery Info</legend> 
    @Html.Partial("DeliveryInfo") 
    </fieldset> 
</div> 

<div class="rightdiv"> 
    <fieldset> 
    <legend>Balance</legend> 
     @Html.Partial("AccountBalance") 
    </fieldset> 

      @if (SessionHelper.ShowPaymentOptions || SessionHelper.ShowHistory) 
      { 
       <fieldset> 
       <legend>Account Options</legend> 
       <br/> 

       @using (Html.BeginForm("AccountScreenButton", "Customer", FormMethod.Post)) 
       { 
        <div class="sidebysidebuttons"> 
        <div class="box"> 
         @if (SessionHelper.ShowHistory && SessionHelper.ShowAccountScreenPaymentButton) 
         { 
         <button class="sidebysidebutton1" name="options" value="payment">Make a Payment</button> 
         <button class="sidebysidebutton2" name="options" value="activity">Display Activity</button> 
         } 
         else 
         { 
         if (SessionHelper.ShowAccountScreenPaymentButton) 
         { 
          <button class="leftpaddedsinglebutton" name="options" value="payment">Make a Payment</button> 
         } 

         if (SessionHelper.ShowHistory) 
         { 
          <button class="leftpaddedsinglebutton" name="options" value="activity">Display Activity</button> 
         } 
         } 
        </div> 
        </div> 
       }  
       </fieldset> 
      } 

    <fieldset> 
     <legend>Billing Info</legend> 
     @Html.Partial("BillingInfo", Model) 
    </fieldset> 
</div> 

To jest część mojego SessionHelper do daje wyobrażenie:

public static CustomerData CustomerSessionData 
{ 
    get 
    { 
    try 
    { 
     return (CustomerData) HttpContext.Current.Session["CustomerSessionData"]; 
    } 
    catch (Exception) 
    { 
     return null; 
    } 
    } 
    set { HttpContext.Current.Session["CustomerSessionData"] = value; } 
} 

    public static bool ShowPaymentTab 
    { 
     get { return HttpContext.Current.Session["ShowPaymentTab"].ToBool(); } 
     set { HttpContext.Current.Session["ShowPaymentTab"] = value; } 
    } 

Nie jestem pewien były kwestią jest w formie od kiedy Umieściłem punkt przerwania w formularzu, to się nie kończy.

Mam dwa pytania:

  1. Jak debugować gdzie problem jest w formularzu?
  2. Czy mogę nie używać klasy jako sesji i odwoływać się do niej w formularzu? Zakładam, że właśnie tu jest problem.

Odpowiedz

21

Problem polega na tym, że nie definiujesz modelu u góry widoku. Z tego powodu domyślnym typem jest typ dynamic.

Normalnie to nie jest problem, ale trzeba to:

@Html.Partial("BillingInfo", Model) 

To w efekcie przekazując typ dynamiczny do Html.Partial(), która jest co rzuca błąd.

To jest bezsensowne połączenie, po prostu usuń jego część Model i powinno działać. Przekazywanie Modelu jest domyślną operacją, więc nie próbujesz zrobić niczego, co nie byłoby domyślne.

+0

Ha ... Nawet tego nie zauważyłem. Ty! Jakieś pomysły dotyczące debugowania formularza internetowego w mvc? – ErocM

+0

@ErocM - Musisz ustawić kursor bezpośrednio na obiekcie, który chcesz debugować, a następnie naciśnij klawisz F9. Na przykład, jeśli chcesz debugować tę sytuację, umieść kursor na części .Partial i naciśnij klawisz F9. Jeśli tego nie zrobisz, nie dostaniesz odpowiedniego kontekstu. –

+0

Dzięki za pomoc! – ErocM

Powiązane problemy