1

I have a View within my MVC 4 application, whereby the user types in a first and last name and hits the search button. Once they do this, an action in my controller is called

[HttpPost]
public ActionResult ChangeLineManager(RegisterLineManagerModel model, int? id)
{

    if (ModelState.IsValid)
    { 
       if (id == null)
       {
         // Search for person using model.SearchFName and model.SearchLName
       }
       else
       {
         // User has selected manager from returned list of people
       }

    }
}

Once the user performs a search and if data is returned, I list the data

@foreach (var user in Model.LineManagers)
{
  <tr>
   <td>@Html.ActionLink(linkText: "Select Manager", 
       actionName: "ChangeLineManager", 
       controllerName: "Portfolio", 
       routeValues: new { id = (int?)user.ApplicantID }, htmlAttributes: null)
   </td>
  </tr>
}

Ideally, I would like the user to then click the 'Select Manager' link beside their appropriate manager, however, whenever I test this, nothing happens, the ChangeLineManager action within my Controller is not called.

Does anyone have any suggestions on how to fix this?

Thanks for your time.

4

1 回答 1

3

操作链接将呈现到标签。当用户单击此标签时,GET 请求会转到服务器,但在您的控制器中仅 POST ChangeLineManager。你需要添加这样的东西

[HttpGet]
public ActionResult ChangeLineManager(int? id)
{
    //some logic

}
于 2013-09-09T12:02:07.290 回答