Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 22, 2012 01:40 PM by aspmunkee
Member
6 Points
29 Posts
Jul 22, 2012 08:20 AM|LINK
Hi all got myself confused with this syntax
I wish to create a list of items and allow each item to be clickable to send me to a new controller action.
The basic format of the list is handled via:
<h2>Departments</h2> <ul> @foreach (var item in Model.Departments) { <li>@Html.DisplayFor(items => item.DepartmentName)</li> } </ul>
How do I go about implementing html.actionlink in to this with a query parameter of the department ID. I thought the following would be ok:
<h2>Departments</h2> <ul> @foreach (var item in Model.Departments) { <li>@Html.DisplayFor(items => Html.ActionLink(item.DepartmentName,"Index","DepartmentOverview",new{dept=item.DepartmentID}))</li> } </ul>
But no luck I get the error:
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
Any ideas?
All-Star
15346 Points
3142 Posts
Jul 22, 2012 10:58 AM|LINK
try
@foreach (var item in Model.Departments){<li> Html.ActionLink(item.DepartmentName, new{ action="index",dept=item.DepartmentID})</li> }
for reference please check this
http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx
Jul 22, 2012 01:40 PM|LINK
<li>@Html.ActionLink(item.DepartmentName, "index","DepartmentOverview", new { dept = item.DepartmentName },null)</li>
This is what worked in the end. Thanks for the ref
aspmunkee
Member
6 Points
29 Posts
@html.actionlink with @html.displayfor
Jul 22, 2012 08:20 AM|LINK
Hi all got myself confused with this syntax
I wish to create a list of items and allow each item to be clickable to send me to a new controller action.
The basic format of the list is handled via:
<h2>Departments</h2> <ul> @foreach (var item in Model.Departments) { <li>@Html.DisplayFor(items => item.DepartmentName)</li> } </ul>How do I go about implementing html.actionlink in to this with a query parameter of the department ID. I thought the following would be ok:
<h2>Departments</h2> <ul> @foreach (var item in Model.Departments) { <li>@Html.DisplayFor(items => Html.ActionLink(item.DepartmentName,"Index","DepartmentOverview",new{dept=item.DepartmentID}))</li> } </ul>But no luck I get the error:
Any ideas?
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: @html.actionlink with @html.displayfor
Jul 22, 2012 10:58 AM|LINK
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: @html.actionlink with @html.displayfor
Jul 22, 2012 10:58 AM|LINK
for reference please check this
http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx
aspmunkee
Member
6 Points
29 Posts
Re: @html.actionlink with @html.displayfor
Jul 22, 2012 01:40 PM|LINK
<li>@Html.ActionLink(item.DepartmentName, "index","DepartmentOverview", new { dept = item.DepartmentName },null)</li>This is what worked in the end. Thanks for the ref