Question

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.

Was it helpful?

Solution

Action link will render to a tag.When user click this tag,GET request go to the server,but in your controller only POST ChangeLineManager. You need add something like this

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top