Home Why I get error when I try to generate ActionLink?
Reply: 2

Why I get error when I try to generate ActionLink?

Michael
1#
Michael Published in 2017-11-13 12:43:18Z

I have this HtmlHelper:

@foreach (var item in Model) 
{
<tr>
    <td>
        @Html.ActionLink(modelItem => item.LayoutID, "someAction");
    </td>        
</tr>
}

On this row,

@Html.ActionLink(modelItem => item.LayoutID, "someAction");

i get this error:

CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type

Why do I get the above error ? The LayoutID is of string type.

EDIT Improved Formatting

Shyju
2#
Shyju Reply to 2017-11-13 12:50:03Z

The first parameter of ActionLink method has to be a string which will appear as the anchor tag text. You are trying to pass a lamda expression.

@foreach(var item in Model)
{
   <tr>
      <td> @Html.ActionLink(item.LayoutID, "someAction") </td>
   </tr>
}
Hiren Korat
3#
Hiren Korat Reply to 2017-11-13 13:06:48Z

you can not use modelitem as parameter in actionlink.actionlink must have string value as parameter try below code:

   @Html.ActionLink(item.LayoutID, "someAction")

or i will suggest you to direct write down string

 @Html.ActionLink("View Report", "someAction")
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296355 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO