'System.Web.Mvc.HtmlHelper'没有适用的名为'Partial'的方法 [英] 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial'

查看:135
本文介绍了'System.Web.Mvc.HtmlHelper'没有适用的名为'Partial'的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

错误CS1973:"System.Web.Mvc.HtmlHelper"不适用 名为部分"的方法,但似乎有一个扩展方法 姓名.扩展方法不能动态调度.考虑 强制转换动态参数或调用扩展方法而无需 扩展方法语法.}

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

根据我在此处阅读的内容 Razor View Engine:表达式树可能不包含动态操作,这是由于使用了viewbag(?),而我实际上是在使用Session.

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.

这是我的网络表单:

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

这是我的SessionHelper的一部分,旨在为您提供一个想法:

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.

我有两个问题:

  1. 如何调试表单上的问题?
  2. 我不能将类用作会话并以表格形式引用它吗?我假设这就是问题所在.

推荐答案

您的问题是您没有在视图顶部定义模型.因此,默认类型为dynamic.

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)

实际上,这是将动态类型传递给您的Html.Partial(),这是引发错误的原因.

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

无论如何这都是毫无意义的调用,只需删除其中的Model部分即可.无论如何,传递模型是默认操作,因此您不会尝试做不是默认操作的事情.

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.

这篇关于'System.Web.Mvc.HtmlHelper'没有适用的名为'Partial'的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆