绑定编辑Asp.Net MVC [英] Bind on edit Asp.Net MVC
问题描述
在这个问题上 ModelBinding asp.net MVC列表我回答如何绑定在创建操作。但我怎么同一个电影类绑定它标记propertie上一个编辑动作?
on this question ModelBinding asp.net MVC List I was answered how to bind on a create action. But How I bind the same Movie class with it tags propertie on an edit action?
因为当我这样做:
public ActionResult Edit(string movieid)
{
if(!string.IsNullOrEmpty(movieid))
{
ViewBag.Edit = true;
var movie= db.GetCollection().FindOne(new { Name = movieid});
if(movieid== null)
throw new HttpException(404, "Movie not found");
return View(movie);
}
return RedirectToAction("Index","Home");
}
在在输入文本查看我得到:System.Collections.Generic.List`1 [System.String]
On the View at the input text I get: System.Collections.Generic.List`1[System.String]
我如何绑定列表中输入文本,在渲染的看法?
How I bind the list to an Input text, on the render of the view?
谢谢!
推荐答案
您可以在一个文本框使用渲染标签(字符串)列表
you can render your list of tags (string) in one textbox using
@Html.TextBoxFor(x => x.Tags, new { @Value = string.Join(",", Model.Tags) })
如果您已实现自定义模型粘合剂如达林在他的回答提出您的简称,它会再次绑定到点燃服务器端代码
and if you have implemented custom model binder as Darin suggested in his answer you referred to, it will bind again to Tags lit on server side
这篇关于绑定编辑Asp.Net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!