2012-01-20 18 views
1

内ActionLinkのとエラー...私はそれにかなり新しいだと私は、グリッド内のActionLinkのを生成し、トラブルのビットを持っていMVCレイザー - カミソリ - - 私はMVCを使用していたグリッド

@grid.GetHtml(
      //Some grid setting stuff here 
      columns: grid.Columns(
       grid.Column(null, null, 
        @<div class="vehicleResult"> 

          @{ 
           var text = string.Format("{0} {1} {2}", item.Value.GetPropertyValue("Manufacturer"), item.Value.GetPropertyValue("Shell Shape"), item.Value.GetPropertyValue("Model")); 
           @Html.ActionLink(text, MVC.Search.ActionNames.VehicleView, MVC.Search.Name, new { Id = item.Id }, new { }); 
          } 

         <a>@string.Format("{0} {1} {2}", item.Value.GetPropertyValue("Manufacturer"), item.Value.GetPropertyValue("Shell Shape"), item.Value.GetPropertyValue("Model"))</a> 
      ))) 

<>最後のタグが正常に動作しますが、私はActionLinkのに介して送信され

@string.Format("{0} {1} {2}", item.Value.GetPropertyValue("Manufacturer"), item.Value.GetPropertyValue("Shell Shape"), item.Value.GetPropertyValue("Model")) 

(上記ビット)すなわち<>タグからテキストをしたいです。また、私がしなければ

...

var text = "blah"; 
@Html.ActionLink(text, MVC.Search.ActionNames.VehicleView, MVC.Search.Name, new { Id = item.Id }, new { }); 

は、それがいいのよ - それは、彼らが一緒にいるとき、それは...私が取得エラーが動作しないだけだ...

System.Web.Mvc.HtmlHelper<GIT.RetailWebsite.App.ViewModels.VehicleSearchModel> 
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.  
d:\TFSProjects\Retail Website\Main\src\Retail Website\GIT.RetailWebsite.App\Views\Search\_grsResultsGrid.cshtml 31 GIT.RetailWebsite.App 

誰でも助けてくれますか?

答えて

3

dynamictext変数を拡張メソッド(ActionLink)で使用しようとしていて、拡張メソッドを呼び出すときに動的引数がサポートされていないため、例外がスローされます。
dynamicitem引数から構成されているため、変数dynamicがあります。それはあなたが何ができるかを説明し、少し不可解な例外メッセージが、

@Html.ActionLink((string)text, 
    MVC.Search.ActionNames.VehicleView, 
    MVC.Search.Name, new { Id = item.Id }, new { }); 

または静的メソッドとして拡張メソッドを呼び出します:

@LinkExtensions.ActionLink(Html, text, 
    MVC.Search.ActionNames.VehicleView, 
    MVC.Search.Name, new { Id = item.Id }, new { }); 

がdymanic引数をキャスト

関連する問題