我目前有这种方法:
public ActionResult Edit([Bind(Include =
"description,tags,files,editFiles")] Task mydata, int keyId){
我想从我的editFiles
模型中移除Task
并将此方法修改为:
public ActionResult Edit([Bind(Include =
"description,tags,files")] Task mydata, int keyId, string editFiles){
我的radiobutton目前看起来像这样:
@Html.RadioButtonFor(model => model.editFiles, "no change", new { @checked = true }) Do not change files
@Html.RadioButtonFor(model => model.editFiles, "delete") Delete old files
我完成此任务的正确方法是什么?
答案 0 :(得分:1)
我会为编辑视图创建一个新的viewmodel,这个viewmodel可以从Task
类继承。
public class EditTaskVM : Task
{
public bool IsEdit { set;get; }
//Other edit related properties as needed.
}
在您的GET操作方法中(对于编辑),返回此新视图模型的实例,我的编辑视图将强烈输入到此新EditTaskVM
类
并在视图中使用IsEdit
属性
@Html.RadioButtonFor(model => model.IsEdit,"nochange", new { @checked = true })No change
@Html.RadioButtonFor(model => model.IsEdit,"delete") Delete old files
对于 HttpPost 操作方法,
[HttpPost]
public ActionResult Edit(EditTaskVM model)
{
// Do your stuff here
//check for model.IsEdit
// TO DO : Redirect (PRG pattern)
}