2

我有一个显示模型的视图,例如:

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 来完成吗?

提前致谢

4

1 回答 1

2

您的DeleteNote操作需要两个参数。我认为如果您将其更改ActionLink为:

Ajax.ActionLink("Delete", "DeleteNote", new { modelId = [modelId], noteId = [noteId] }, new AjaxOptions { HttpMethod = "POST" })
于 2011-06-23T00:14:20.060 回答