views:

419

answers:

1

Hey

I was using this custom html helper in asp.net mvc 1.0 but now I am trying to use it in a 2.0 project and it crashes

http://blog.pagedesigners.co.nz/archive/2009/07/15/asp.net-mvc-ndash-validation-summary-with-2-forms-amp-1.aspx

This is the error I get.

System.MissingMethodException was unhandled by user code
  Message=Method not found: 'System.String System.Web.Mvc.Html.ValidationExtensions.ValidationSummary(System.Web.Mvc.HtmlHelper)'.
  Source=CustomHtmlHelpers
  StackTrace:
       at CustomHtmlHelpers.ActionValidationSummaryHelper.ActionValidationSummary(HtmlHelper html, String action)
       at ASP.views_signin_signin_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in  SignIn.aspx:line 23
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Control.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)   Site.Master:line 64
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Control.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Page.Render(HtmlTextWriter writer)
       at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

My other html helpers in the same library do work. I added the namespace into the webconfig.

Code I have

 public static class ActionValidationSummaryHelper
    {
        public static MvcHtmlString ActionValidationSummary(this HtmlHelper html, string action)
        {
            string currentAction = html.ViewContext.RouteData.Values["action"].ToString();

            if (currentAction.ToLower() == action.ToLower())
            {
                return html.ValidationSummary();
            }

            return MvcHtmlString.Empty;
        }

    }
A: 

Hi @chobo2,

Its complaining that it can't find a ValidationSummery method that returns a string... so I'm thinking it might be because HtmlHelper.ValidationSummary() now returns an instance of MvcHtmlString and not System.String.

I haven't tested this, but try changing your extension method to:

public static MvcHtmlString ActionValidationSummary(this HtmlHelper html, string action)
{
    string currentAction = html.ViewContext.RouteData.Values["action"].ToString();

    if (currentAction.ToLower() == action.ToLower())
        return html.ValidationSummary();

    return MvcHtmlString.Empty;
}

Let me know if that works or not :-)

HTHs,
Charles

Charlino
Hmm no it seems to still not work. I am getting the same error.
chobo2
It's still giving the exact same exception? Is the extension method in your web project or a separate class library?
Charlino
Seems to be the same exception. It is in a separate class library.
chobo2
At the risk of telling you how to suck eggs... Are both projects referencing the same asp.net mvc dll?
Charlino
You mean are they using the same version? Since at first they where not but if you try to use MvcHtmlString and your referencing the asp.net mvc 1.0 dll it will not let you compile as it seems to not have existed in mvc 1.0. So I did change the library to use 2.0. Is it working on your computer? If so can you email me the solution?
chobo2