2014-11-04 34 views
0

在MVC 4項目中,我嘗試了pass parameter value,如下所示,但是我的failed due to syntax無法在mvc中的Html.EditableGridView中傳遞參數值cshtml

在.cshtml文件

@(Html.EditableGridView<MyModel>("TestGridView",Model,Server.MapPath("~/XmlFile/Test.xml"),GridRowSelectionMode.Multiple, 
    new { cssObj = "genericContentCss", url = "/Test/GetMyPartial?mode=Edit&id=" })) 

在URL想通過id參數值一樣[email protected]

,但它不工作,我失去了一些東西非常小,我試過谷歌,但沒有做到這一點任何人都可以給我提供線索

謝謝

回答

1

這個怎麼樣:

@Html.EditableGridView<MyModel>("TestGridView", 
           Model, 
           Server.MapPath("~/XmlFile/Test.xml"), 
           GridRowSelectionMode.Multiple, 
           new { cssObj = "genericContentCss", 
             url = "/Test/GetMyPartial?mode=Edit&id="+Model.Id 
            } 
           ) 

,或者您可以使用Url.Action()

@Html.EditableGridView<MyModel>("TestGridView", 
            Model, 
            Server.MapPath("~/XmlFile/Test.xml"), 
            GridRowSelectionMode.Multiple, 
            new { cssObj = "genericContentCss", 
              url = Url.Action("GetMyPartial","Test",new { mode="Edit" , id=Model.Id }) 
             } 
            ) 
+0

我的模型是一個List <> :(不能得到Model.Id:

url = Url.Action("GetMyPartial","Test",new { mode="Edit" , id=Model.Id }) 
在上面的代碼

'Id'直接應該使用@ Model.Select(t => t.Id)''它會採用當前選定的行ID' 變得 '/ GetMyPartial/Test/S ystem.Linq.Enumerable%2bWhereSelectListIterator%602%5BMyModel%2cSystem.Guid%5D?mode = Edit' – Neo 2014-11-04 18:44:53

+1

@ashish如果它是一個集合,那麼你想要哪個id? – Dismissile 2014-11-04 20:21:48

+0

@ehsan Sajjad我想要選擇的行ID列 – Neo 2014-11-05 04:08:35