Html-Code.ActionLink Wert von ViewBag
In ASP MVC C# ich geputtet eine Liste(Autos) im ViewBag.Autos, nun möchte ich einen actionlink mit dem Titel jedes Autos, wie dieses:
@if (ViewBag.cars != null)
{
foreach (var car in ViewBag.cars)
{
<h4>@Html.ActionLink(@car.title, "Detail", "Cars", new { id = @car.id }, new { @class = "more markered" })</h4>
}
}
Den Fehler bekomme ich wenn ich @Auto.Titel oder nur Auto.Titel als Wert, ich bekomme diese Fehlermeldung:
CS1973: 'System.Web.Mvc.HtmlHelper<AutoProject.Models.CarDetails>' has no applicable method named 'ActionLink' but appears to have an extension method by that name.
Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
Was soll ich füllen Sie als ersten parameter der Actionlink?
InformationsquelleAutor francisMi | 2014-01-09
Du musst angemeldet sein, um einen Kommentar abzugeben.
Weil
car
ist dynamisch, so dass Sie nicht wissen, was die entsprechende Erweiterung Methode sein könnte. Wenn Sie die Umwandlungtitle
zustring
, undid
zuobject
, es werde in Ordnung sein:Ihre andere option ist, um ein stark typisiertes ViewModel.
InformationsquelleAutor John Gibb
Versuchen, weisen Sie Ihren
car.title
einer Variablen zuerst, dann verwenden Sie die variableInformationsquelleAutor Selman Genç
Versuchen Sie dies:
ps würde ich auch machen, Ihre Eigenschaften Großbuchstaben, anstatt niedriger.
Versuchen Sie, die oben anstelle, sorry verpasste die foreach-out
InformationsquelleAutor hutchonoid