我的观点:Asp.net MVC GridView的编辑列选项
<%= Html.Grid(Model.data).Columns(column => {
column.For(x => x.results)
.Action(item => Html.ActionLink(item.results,"Edit").ToString(),
item => Html.TextBox("result",item.results).ToString(),
item => (Model.data == item))
.Named("Results");
column.For(x => x.refId)
.Named("Reference ID");
column.For(x => x.fileLocation)
.Named("File Location");
})
.Attributes(style => "width:100%", border => 1)
而且控制器的样子:
public ActionResult Index()
{
// IEnumerable<TranslationResults> results;
StringSearchResultsModelIndex modelInstance = new StringSearchResultsModelIndex();
modelInstance.getData();
return View("SearchGUIString", modelInstance);
}
数据:
public class StringSearchResultsModelIndex : IStringSearchResultsModelIndex
{
private IEnumerable<StringSearchResultModel> m_data;
private string id;
public IEnumerable<StringSearchResultModel> getData()
{
List<StringSearchResultModel> models = new List<StringSearchResultModel>();
StringSearchResultModel _sModel = new StringSearchResultModel();
for (int i = 1; i < 11; i++)
{
_sModel = new StringSearchResultModel();
_sModel.fileLocation = "Location" + i;
_sModel.refId = "refID" + i;
_sModel.results = "results" + i;
models.Add(_sModel);
}
m_data = models;
return models;
}
public IEnumerable<StringSearchResultModel> data { get { return m_data; } set { m_data = value; } }
public string SelectedRowID {get {return id ; } set { id = value; } }
}
当我点击编辑按钮从ActionLink,我被引导到/搜索/编辑页面,我明白,我需要在控制器中有一些代码/ /搜索/编辑,但我没有得到我可以在结果单元格中编辑文本的文本框。我是新来的MVC任何人都可以指导我,我应该从这里出发,有什么建议吗?
我怎么会知道我在这里检查什么平等,Model.data是对象列表类型“搜索”具有不同的属性,它看起来像项目将只是一个对象,我怎么可以比较找到我正在寻找哪一个那个清单?我现在彻底困惑:(。你可以在这个.action方法上抛出一些提示,并告诉如何将它与行关联起来吗? – remo 2011-04-05 13:58:00
@sharma我已经更新了我的答案,希望能够说清楚。 – 2011-04-05 14:45:04