1

I want to select a line of references to get the list of athor reference associat , this is the code of my view :

<table class="table">
<tr>
    <th>
        @Html.DisplayNameFor(model => model.Réf_OE)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.GENER_MOTORS)
    </th>
    <th></th>
</tr>
@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Réf_OE)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.GENER_MOTORS)
    </td>
    <td>
        @Html.ActionLink("Select", "Select", new { Réf = item.Réf_OE }) 
</tr>  
}

This the code of my select method :

 [HttpGet]
    public ActionResult Select(string Réf)
    {
        if (Réf != null)
        {
            var autres_ref = db.Autre_Références.Where(c => c.Réf_id == Réf).ToList();
            ViewBag.autres_ref = autres_ref;
            return RedirectToAction("Index", "Référence_Consctructeur");
        }
        else
        {
            return RedirectToAction("Create", "Référence_Consctructeur");
        }
        return RedirectToAction("Index", "Référence_Construscteur");
    }

and i put the cursor on select it shows :

http://localhost:56616/R%C3%A9f%C3%A9rence_Consctructeur/Select/7700308756

I didn't understand why the paramter passed to select is null please help.

2
  • 2
    Because the parameter name is Réf and not id. Commented Dec 1, 2016 at 20:21
  • thank you , i fixed it now , by changing the name of parametre Commented Dec 1, 2016 at 20:37

1 Answer 1

1

The parameter name you are passing in your ActionLink should match with the parameter name in your action:

@Html.ActionLink("Select", "Select", new { Réf= item.Réf_OE }) 

Or change the parameter name of your action:

 public ActionResult Select(string id){...}
Sign up to request clarification or add additional context in comments.

2 Comments

And both actions are defined in the same controller? That should fix the binding problem
thanks for your help it works fine now , :D the problem was because of name of parametre

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.