我收到此錯誤:「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 : An expression tree may not contain a dynamic operation的是,它是由於使用viewbag(?)我真的在使用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給你一個想法的一部分:
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; }
}
我不知道是該問題的形式,因爲當我在表格中放置了一個斷點,它並不止於此。
我有兩個問題:
- 如何調試那些問題的形式呢?
- 我不能將類用作會話並在表單中引用它嗎?我假設這是問題所在。
哈...我甚至沒有注意到這一點。泰!有關在mvc中調試Web表單的任何想法? – ErocM 2015-02-11 22:03:27
@ErocM - 您需要將光標直接設置在要調試的對象上,然後按F9。例如,如果您想調試這種情況,您可以將光標放在.Partial部件上,然後按F9鍵。如果你不這樣做,它不會得到正確的背景。 – 2015-02-11 22:06:37
感謝您的幫助! – ErocM 2015-02-11 22:07:32