Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial'

I am getting this error:

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

From what I read here Razor View Engine : An expression tree may not contain a dynamic operation is that it is due to using viewbag(?) which I am really using Session.

This is my web form:

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

This is part of my SessionHelper to give you an 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; }
    }

I'm not sure were the issue is in the form since when I put a break point in the form, it does not stop there.

I have two questions:

  1. How do I debug where the issue is on the form?
  2. Can I not use a class as a session and reference it in the form? I'm assuming that is where the issue is at.
like image 409
ErocM Avatar asked Feb 11 '15 21:02

ErocM


1 Answers

Your problem is that you don't define a model at the top of your view. Because of this, the default type is of type dynamic.

Normally, this isn't a problem, but you have this:

@Html.Partial("BillingInfo", Model)

This is, in effect, passing a dynamic type to your Html.Partial(), which is what is throwing the error.

This is a pointless call anyways, just remove the Model part of it and it should work. Passing the Model is the default operation anyways, so you are not trying to do anything that wouldn't be the default.

like image 152
Erik Funkenbusch Avatar answered Dec 22 '22 23:12

Erik Funkenbusch