2015-02-11 7 views
14

मैं इस त्रुटि हो रही है: मैं यहाँ क्या पढ़ा Razor View Engine : An expression tree may not contain a dynamic operation कि यह viewbag का उपयोग कर की वजह से है से'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."}

(?) जो मैं वास्तव में सत्र का उपयोग कर रहा हूँ।

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

मुझे यकीन है कि थे मुद्दा कब से रूप में है नहीं कर रहा हूँ:

@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 आप जानकारी देने के लिए का हिस्सा है:

यह मेरा वेब रूप है मैंने फॉर्म में ब्रेक पॉइंट डाला, यह वहां नहीं रुकता है।

मैं दो प्रश्न हैं:

  1. मैं कैसे डीबग करूँ जहां इस मुद्दे को फार्म पर है?
  2. क्या मैं कक्षा के रूप में कक्षा का उपयोग नहीं कर सकता और इसे फॉर्म में संदर्भित कर सकता हूं? मुझे लगता है कि यह मुद्दा है जहां मुद्दा है।

उत्तर

21

आपकी समस्या यह है कि आप अपने विचार के शीर्ष पर एक मॉडल को परिभाषित नहीं करते हैं। इस वजह से, डिफ़ॉल्ट प्रकार dynamic प्रकार है।

आम तौर पर, यह एक समस्या नहीं है, लेकिन आप इस राशि:

@Html.Partial("BillingInfo", Model) 

यह वह जगह है, प्रभाव में, अपने Html.Partial(), जो हैं तो त्रुटि फेंक रहा है करने के लिए एक गतिशील प्रकार गुजर।

यह वैसे भी एक व्यर्थ कॉल है, बस इसके मॉडल हिस्से को हटा दें और इसे काम करना चाहिए। मॉडल को पास करना डिफ़ॉल्ट ऑपरेशन है, इसलिए आप कुछ भी करने की कोशिश नहीं कर रहे हैं जो डिफ़ॉल्ट नहीं होगा।

+0

हा ... मैंने यह भी ध्यान नहीं दिया। Ty! एमवीसी में एक वेब फॉर्म डीबग करने पर कोई विचार? – ErocM

+0

@ErocM - आपको कर्सर को सीधे उस ऑब्जेक्ट पर सेट करने की आवश्यकता है जिसे आप डिबग करना चाहते हैं, फिर F9 दबाएं। उदाहरण के लिए, यदि आप इस स्थिति को डीबग करना चाहते हैं, तो आप कर्सर को पार्टिकल भाग पर रखेंगे, और F9 दबाएं। यदि आप ऐसा नहीं करते हैं, तो इसका सही संदर्भ नहीं मिलेगा। –

+0

मदद के लिए धन्यवाद! – ErocM

संबंधित मुद्दे