Reputation: 8426
In ASP.NET MVC4, is there a way to use a static method in a Razor view? My Intellisense is giving me an error when I try:
<a href="@Url.Action(
"Delete",
"Editor",
new { viewContext = "report", Ids = new int[Int32(Model.ID)] }
)">Delete</a>
I am able to use the Url.Action
method with no problems, but when I try to use the Int32
method, it throws "'int' is a 'type' but is used like a 'variable'", an error usually associated with, as I said, using a static method.
What's going on?
Upvotes: 0
Views: 96
Reputation: 313
Use Either
<a href="@Url.Action(
"Delete",
"Editor",
new { viewContext = "report", Ids = @Model.ID }
)">Delete</a>
Or
<a href="@Url.Action(
"Delete",
"Editor",
new { viewContext = "report", Ids = Convert.ToInt32(Model.ID) }
)">Delete</a>
Or
@Html.ActionLink("Delete", "Editor", new { viewContext = "report",Ids = Model.ID })
Upvotes: 1
Reputation: 16388
Personally, I'd use Convert
.
<a href="@Url.Action(
"Delete",
"Editor",
new { viewContext = "report", Ids = new int[Convert.ToInt32(Model.ID)] }
)">Delete</a>
Upvotes: 1