2015-02-11 19 views
14

sto ottenendo questo errore:'System.Web.Mvc.HtmlHelper' non ha un metodo applicabile chiamato 'parziale'

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."}

Da quello che ho letto qui Razor View Engine : An expression tree may not contain a dynamic operation è che è dovuta all'utilizzo viewbag (?) che sto usando davvero Session.

Questo è il mio modulo web:

@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> 

Questo fa parte del mio SessionHelper per dare un'idea:

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

Non sono sicuro che fosse il problema è nella forma da quando Ho messo un punto di interruzione nella forma, non si ferma qui.

Ho due domande:

  1. Come si esegue il debug in cui il problema è sul modulo?
  2. Posso non utilizzare una classe come sessione e farne riferimento nel modulo? Presumo che sia qui che si trova il problema.

risposta

21

Il problema è che non si definisce un modello nella parte superiore della vista. Per questo motivo, il tipo predefinito è di tipo dynamic.

Normalmente, questo non è un problema, ma avete presente:

@Html.Partial("BillingInfo", Model) 

Questo è, in effetti, il superamento di un tipo dinamico al vostro Html.Partial(), che è ciò che sta gettando l'errore.

Questa è una chiamata inutile comunque, basta rimuovere la parte del modello e dovrebbe funzionare. Passare il modello è comunque l'operazione predefinita, quindi non si sta tentando di fare qualcosa che non sarebbe l'impostazione predefinita.

+0

Ha ... Non l'ho nemmeno notato. Ty! Qualche idea sul debug di un modulo web in mvc? – ErocM

+0

@ErocM - È necessario impostare il cursore direttamente sull'oggetto che si desidera eseguire il debug, quindi premere F9. Ad esempio, se vuoi eseguire il debug di questa situazione, posiziona il cursore sulla parte .Partial e premi F9. Se non lo fai, non otterrà il contesto giusto. –

+0

Grazie per l'aiuto! – ErocM

Problemi correlati