1

I am getting null value in the parameter of my action method.

this is my action method

 [HttpGet]
    public ActionResult ProjectData(int? formId)
     {
                if (formId == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }

                return View();

            }
     }

and this is my view of actionlink

@foreach (var projects in Model)
                {
                    int formId = Convert.ToInt32(@projects.FormId);

                <tr>
                    <td>@projects.Serial</td>
                    <td>@projects.ProjectName</td>
                    @*<td><a href="#">@projects.SurveyName</a></td>*@
                    @*<td>@Html.ActionLink(@projects.SurveyName, "ActionName", new { id = @projects.FormId })</td>*@

                    <td>@Html.ActionLink(@projects.SurveyName, "ProjectData" , "Home", new {id = formId}, null)</td>
                    <td>@projects.TotalSubmission</td>
                    <td>@projects.LastSubmissionTime</td>
                    <td>@projects.SubmissionToday</td>

                </tr>


                }

I am using list of user defined type model:

@model IEnumerable<MVC.ProjectInformation>

When I click on actionlink under the loop it should send id to the controller actionmethod but I get the parameter null always. Specific Actionlink:

@Html.ActionLink(@projects.SurveyName, "ProjectData" , "Home", new {id = formId}, null)

I can see the id by debugging on the View but on controller actionmethod I cannot get that id value.

1 Answer 1

2

The ActionLink's routeValues object properties need to match the parameters of the controller action.

Currently it is

new { id = formId }

which would not match the parameter of the ProjectData

public ActionResult ProjectData(int? formId)

Update to match

@Html.ActionLink(@projects.SurveyName, "ProjectData" , "Home", new {formId = formId}, null)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.