2011-06-22 95 views
2

我有顯示模式如一個觀點:MVC 3 Ajax.ActionLink通父模型屬性

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實現的呢?

在此先感謝

回答

2

DeleteNote動作需要兩個參數。我認爲它應該工作,如果您將ActionLink更改爲:

Ajax.ActionLink("Delete", "DeleteNote", new { modelId = [modelId], noteId = [noteId] }, new AjaxOptions { HttpMethod = "POST" })