2013-06-04 84 views
0

我有把每個項目存檔,現在我想顯示所有歸檔項目的選擇項目控制器

$.post("@Url.Action("ShowArchive", "Project")"); 

ShowArchive:

public JsonResult ShowArchive(int id) 
{ 
    List<Project> projectList = (List<Project>)projectService.ShowArchivebyid(id); 
    return Json(projectList.ConvertAll<object>(Project.ToJsonObject), JsonRequestBehavior.AllowGet); 
} 

public IEnumerable<Project> ShowArchivebyid(int id) 
{ 
    Project project = GetProject(id); 
    Expression<Func<Project, bool>> constraint = null; 
    constraint = e => (e.Archive == 1); 
    IEnumerable<Project> result_list = projectRepository.GetMany(constraint); 

    return result_list.ToList<Project>(); 
} 
在JavaScript控制檯

POST http://localhost:4991/Project/ShowArchive 500 (Internal Server Error) library.min.js:4 
send library.min.js:4 
f.extend.ajax library.min.js:4 
f.(anonymous function) library.min.js:4 
(anonymous function) localhost/:417 
f.event.dispatch library.min.js:3 
h.handle.i 
+2

傳遞'id'參數的動作或使其可爲空:'詮釋? id'。 – Zabavsky

+1

對於初學者,你沒有傳遞一個id到ShowArchive – Johan

回答

1

您需要更新的東西的JavaScript調用像...

$.post("@Url.Action("ShowArchive", "Project", new { id = your_id })"); 

(未經測試)