0

I have a problem. In my View of a product I have a button to add it to cart which looks like this:

<div>
<% using(Html.BeginForm("AddToCart", "Cart")) {%>
    <%: Html.HiddenFor(x => x.id_produktu) %>
    <%: Html.Hidden("returnUrl", Request.Url.PathAndQuery) %>
    <input type="submit" value="Dodaj do koszyka" />
    <% } %>
    <h4><%: Model.cena_produktu.ToString("c")%></h4>

For this line:

<%: Html.Hidden("returnUrl", Request.Url.PathAndQuery) %>

I get an error:

The call is ambiguous between the following methods or properties: 'System.Web.Mvc.TextInputExtensions.Hidden(System.Web.Mvc.HtmlHelper, string, object)' and 'System.Web.Mvc.Html.InputExtensions.Hidden(System.Web.Mvc.HtmlHelper, string, object)'

How to solve this? Thank you in advance.

Lord_Blizzard
  • 25
  • 2
  • 9

1 Answers1

4

Three ways:

  1. Fully qualify the method:

    System.Web.Mvc.Html.Hidden(Html, "returnUrl", Request.Url.PathAndQuery)
    
  2. Make your own static method with a different name that obfuscates the name.

    public static string TheHiddenIWant(this HtmlHelper helper, string name, object value)
    {
        return System.Web.Mvc.Html.Hidden(helper, name, value);
    }
    Html.TheHiddenIWant("returnUrl", Request.Url.PathAndQuery);
    
  3. Don't include the reference or using statement for the extension method you don't want. For example, get rid of using System.Web.Mvc.TextInputExtensions, or just get rid of the reference.

hammar
  • 138,522
  • 17
  • 304
  • 385
  • The first way (slightly changed: `<%: System.Web.Mvc.Html.InputExtensions.Hidden(Html, "returnUrl", Request.Url.PathAndQuery) %>`) helped, thank you! :) – Lord_Blizzard Nov 24 '11 at 09:03