9
votes

I am trying to use the strongly typed view with extensions methods as

<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend>MyUsageViewModel</legend>

        <div class="editor-label">
            <%= Html.LabelFor(model => model.test) %>
        </div>   
                              <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
<% } %>
    <div>
    <%: Html.ActionLink("Back to List", "Index") %>
</div>

I am getting the following error :

The type arguments for method 'System.Web.Mvc.Html.LabelExtensions.LabelFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Help would be appreciated

4
Is your model dynamic? - Jeremy McGee
could you share your model code? - Vic

4 Answers

1
votes

It seems your model doesn't have 'test' property which you are trying to use in Html.LabelFor helper method.

0
votes

Make sure your model properties are public:

public class LocationModel
{
    public double Latitude { get; set; }
    public double Longitude { get; set; }
    public string Name { get; set; }
}
0
votes

The sample code does not show a definition for the type which could be the issue. Make sure it's at the top of the page. I'm on my tablet right now and don't have a sample to copy/paste but the syntax should be @model modelType

If that's not the issue, can you add the model definition and full contents of the view?

0
votes

After moving some code around to different namespaces I was seeing this same issue even though I had updated model references etc correctly. The solution was to go to build and perform a 'Clean Solution' followed by a 'Rebuild Solution'