MVC 3 Ajax.ActionLink Pass Parent Model Property
I have a view which displays a model eg:
public class MyModel()
{
public string name {get;set;}
public IList<Note> notes {get;set;}
}
The view displays all the notes for the model, i am trying to use Ajax.ActionLink to delete a note, but in order to delete a note i need to pass my controller action result the ID of the model.
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.i开发者_开发问答d}, new AjaxOptions{HttpMethod="POST"})
Can this be accomplished with ajax.actionlink?
Thanks in advance
Your DeleteNote
action expects two parameters. I think it should work if you change the ActionLink
to:
Ajax.ActionLink("Delete", "DeleteNote", new { modelId = [modelId], noteId = [noteId] }, new AjaxOptions { HttpMethod = "POST" })
精彩评论