Click here to Skip to main content
15,356,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I am in a view in path "Teams/Search.cshtml" , I want to shift from here to "Players/Edit" with the value player ID. So I wrote the code like:

@Html.ActionLink("Edit", "Edit","Players",new { id = player.PlayerID }) |
@Html.ActionLink("Edit", "Edit",new { id = player.PlayerID }) |
@Html.ActionLink("Edit", "Edit","Players")
Here I can see that first line is " NOT CORRECT ". Second Line is "Correct" but it goes the path"Teams/Edit" and third one goes to "Players/Edit" .

SO third one goes in correct path but how can I send the ID in this path.

Please help me to ahead.
Posted
Comments
jo.him1988 8-Jul-14 4:29am
   
hi i am newbi in mvc, hope this will help you :)
i have made same like country and state example
gridview showing all country id and name with viewStates hyperlink
as similer to your Query players like country and states like player details :)

you have to make on action which get the details of player by id and than that return to your players edit view with that object
like i use action redirect(countrycode)and return that state model to respective view
:) :) :)

//here is Country controller which return country view and states view
public class CountryController : Controller
  {
      public ActionResult Index()
      {
          Data.TestEntities ent = new Data.TestEntities();
          var country = ent.Countries.ToList();
          return View("SearchView", country);
      }
      public ActionResult redirect(int? countryCode)
      {
          Data.TestEntities entity = new Data.TestEntities();
          var states = entity.States.Where(s => s.CountryID == countryCode).ToList();
          return View("ViewStates", states);
      }

  }


//here is country view
@model List<TestMVC4.Data.Country>

@{
    ViewBag.Title = "SearchView";
}

<h2>SearchView</h2>
<table  style="width:60%">
<tr>
<th>Country ID</th>
<th>Country Name</th>
<th>View States</th>
</tr>

@foreach (var country in Model)
{
    <tr>
  <td>@country.CountryID</td>
  <td>@country.CountryName</td>
  <td><big></big>@Html.ActionLink("ViewStates", "redirect", new {countryCode=country.CountryID })</td>
</tr>
}
</table>





// and after click on ViewStates StateView.chtml
@model List<TestMVC4.Data.State>

@{
    ViewBag.Title = "ViewStates";
}

<h2>ViewStates</h2>


<table style="width:60%">
    <tr>
        <th>
           State ID
        </th>
        <th>
           State Name
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.StateID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.StateName)
        </td>
        @*<td>
           
        </td>*@
    </tr>
}
<tr>
<td>
<p>  @Html.ActionLink("back to search", "Index","Country")
</p>
</td>
</tr>
</table>
   
Actually there is no method with following 3 parameters
@Html.ActionLink("Edit", "Edit","Players",new { id = player.PlayerID })
It expects another parameter htmlAttributes object. So pass this object as null
@Html.ActionLink("Edit", "Edit","Players",new { id = player.PlayerID },null) 
   
Comments
rayhan12345 9-Jul-14 0:35am
   
great!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900