我有一个显示模型的视图,例如:
public class MyModel()
{
public string name {get;set;}
public IList<Note> notes {get;set;}
}
视图显示模型的所有注释,我尝试使用Ajax.ActionLink删除注释,但为了删除注释,我需要传递控制器操作结果模型的ID。
public ActionResult DeleteNote(int modelId, int noteId)
{
var franchise = _franchiseRepository.FindById(modelId);
Note note = new Note(noteId);
franchise.RemoveNote(note);
_franchiseRepository.SaveOrUpdate(franchise);
return View();
}
Ajax.ActionLink("Delete", "DeleteNote", new {id=item.id}, new AjaxOptions{HttpMethod="POST"})
可以用ajax.actionlink完成吗?
提前致谢
答案 0 :(得分:2)
您的DeleteNote
操作需要两个参数。我认为如果您将ActionLink
更改为:
Ajax.ActionLink("Delete", "DeleteNote", new { modelId = [modelId], noteId = [noteId] }, new AjaxOptions { HttpMethod = "POST" })