erichexter / twitter.bootstrap.mvc

nuget package to make bootstrap easy with mvc4
Apache License 2.0
248 stars 134 forks source link

Create.cshtml fails build #12

Closed roryprimrose closed 11 years ago

roryprimrose commented 11 years ago

Just installed the nuget package and I get this from a build:

\Views\Shared\Create.cshtml(11): error CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Label' and the best extension method overload 'System.Web.Mvc.Html.LabelExtensions.Label(System.Web.Mvc.HtmlHelper, string, string)' has some invalid arguments \Views\Shared\Create.cshtml(11): error CS1503: Argument 3: cannot convert from 'AnonymousType#1' to 'string'

There is no overload that takes new { @class = "control-label" } as a parameter.

roryprimrose commented 11 years ago

I added the following extension methods to get it to compile (haven't tested yet though).

    public static MvcHtmlString Label(this HtmlHelper html, string expression, string labelText, object htmlAttributes)
    {
        return LabelHelper(html, ModelMetadata.FromStringExpression(expression, html.ViewData), expression, labelText, htmlAttributes);
    }

    private static MvcHtmlString LabelHelper(
        HtmlHelper html, 
        ModelMetadata metadata, 
        string htmlFieldName, 
        string labelText = null, 
        object htmlAttributes = null)
    {
        string str = labelText ?? (metadata.DisplayName ?? (metadata.PropertyName ?? htmlFieldName.Split(
            new[]
            {
                '.'
            }).Last()));

        if (string.IsNullOrEmpty(str))
        {
            return MvcHtmlString.Empty;
        }

        TagBuilder tagBuilder = new TagBuilder("label");
        tagBuilder.Attributes.Add(
            "for", 
            TagBuilder.CreateSanitizedId(html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName)));
        tagBuilder.SetInnerText(str);

        RouteValueDictionary attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

        tagBuilder.MergeAttributes(attributes);
        return tagBuilder.ToMvcHtmlString(TagRenderMode.Normal);
    }

erichexter commented 11 years ago

I am not able to reproduce this.. Can you give me some more details of how you did this.

The steps I followed were:

  1. open vs2012
  2. create a new mvc 4 - Empty project
  3. in nuget console window: install-package twitter.bootstrap.mv4
  4. in nuget console window: install-package twitter.bootstrap.mvc4.sample
  5. F5 build and Debug.
roryprimrose commented 11 years ago

Solved. I did as you suggested and then compared the assembly references. Looks like I had an MVC3 binary being resolved from somewhere. VS had a hint path to a nuget package that no longer existed. The web.config under Views was also pointing to MVC3 and there were MVC3 assemblies being brought in via the root web.config.

I’ve added the MVC4 nuget package, updated the config files and it is all fixed up now.

Thanks

From: Eric Hexter Sent: ‎24‎ ‎November‎ ‎2012 ‎2‎:‎45‎ ‎AM To: erichexter/twitter.bootstrap.mvc CC: Rory Primrose Subject: Re: [twitter.bootstrap.mvc] Create.cshtml fails build (#12)

I am not able to reproduce this.. Can you give me some more details of how you did this.

The steps I followed were:

  1. open vs2012
  2. create a new mvc 4 - Empty project
  3. in nuget console window: install-package twitter.bootstrap.mv4
  4. in nuget console window: install-package twitter.bootstrap.mvc4.sample
  5. F5 build and Debug.

— Reply to this email directly or view it on GitHubhttps://github.com/erichexter/twitter.bootstrap.mvc/issues/12#issuecomment-10663069.

erichexter commented 11 years ago

glad you got it resolved..