Reputation: 2244
I currently have this method:
public ActionResult Edit([Bind(Include =
"description,tags,files,editFiles")] Task mydata, int keyId){
and I'd like to remove editFiles
from my Task
model and modify this method to be:
public ActionResult Edit([Bind(Include =
"description,tags,files")] Task mydata, int keyId, string editFiles){
My radiobuttons currently look like this:
@Html.RadioButtonFor(model => model.editFiles, "no change", new { @checked = true }) Do not change files
@Html.RadioButtonFor(model => model.editFiles, "delete") Delete old files
What is the right way for me to accomplish this?
Upvotes: 0
Views: 550
Reputation: 218702
I would create a new viewmodel for the edit view, this viewmodel can inherit from the Task
class.
public class EditTaskVM : Task
{
public bool IsEdit { set;get; }
//Other edit related properties as needed.
}
in your GET action method (For Edit), Return an instance of this new view model, and my Edit view will be strongly typed to this new EditTaskVM
class
and in the view, use the IsEdit
property
@Html.RadioButtonFor(model => model.IsEdit,"nochange", new { @checked = true })No change
@Html.RadioButtonFor(model => model.IsEdit,"delete") Delete old files
For your HttpPost action method,
[HttpPost]
public ActionResult Edit(EditTaskVM model)
{
// Do your stuff here
//check for model.IsEdit
// TO DO : Redirect (PRG pattern)
}
Upvotes: 1