shalini garg
shalini garg

Reputation: 21

redirect value from one view to another

I need to pass selected table row values from one view to another. My code looks like this.

<table id="tableid">
  <thead>
    <tr>
      <th id="Sno">S No</th>
      <th>Name</th>
      <th>Status</th>
      <th>Action</th>
      </tr>
  </thead>
  <tbody >
    @foreach (var sd in Model.Details)
    {

      <tr id="trid">
        <td>@sd .Id</td>
        <td>@sd .Name</td>
        <td>@sd .Status</td>
        <td>

          <a id="actionId"   onclick="Clickfn(@sd .Id)"  >
          </a>
          <script>
            function Clickfn(Id) {
var url = '@Url.Action("UpdateCam", "Campaignboard", new {id = -1})';
 window.location.href = url.replace('-1', Id);
               }
          </script>

          </td>
      </tr>
    }
  </tbody>
</table>

I want to pass selected row Details from this view to another view . How i can achieve that.

Upvotes: 1

Views: 903

Answers (3)

Dumi
Dumi

Reputation: 1444

 function Clickfn(Id, Name, Status) 
 {
    var url = "@Url.Action("UpdateCam", "Campaignboard", new {id = _Id, name=_Name, status=_Status})".replace("_Id", Id).replace("_Name", Name).replace("_Status", Status);
    window.location.href = url;               
 }

Your action will be,

Public ActionResult UpdateCam(int id, string name, string status)
{
    // TODO
}

Upvotes: 0

user3559349
user3559349

Reputation:

Just use the ActionLink helper (and dump the javascript)

@foreach (var sd in Model.Details)
{
  ....
  <td>@Html.ActionLink("SomeTextLabel", "UpdateCam", "Campaignboard", new { id = sd .Id })</td>
  ...
}

Upvotes: 1

Yuliam Chandra
Yuliam Chandra

Reputation: 14640

You can just append the string.

var url = '@Url.Action("UpdateCam", "Campaignboard")';
window.location.href = url + '/' + Id;

By default based on route configuration, the query will be routed to id.

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

Upvotes: 0

Related Questions