Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • RedirectToAction in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 43
    Comment on it

    In the MVC projects we pass the action to the view and passing the model object if necessary into the view.

     

     

     

     

    Then we have scenarios where we dont want to return anything or we want to redirect from one action to the another view which the action is not meant for.

     

     

     

     

    So in that case we will use the method that will redirect the controller to view which we have mentioned.

     

     

     

    RedirectToAction is that method which will do it from the controller action into the view.

     

     

     

      [HttpPost]
            public ActionResult SaveDetails(EmployeeModel EmpMod)
            {
                EmpRep = new EmployeeRepository();
                EmpMod = EmpRep.SaveDetails(EmpMod);
                return RedirectToAction("Index");
            }
    

     

     

     

    This will redirect the action to the Index view which is used to display the detail of the employee.

     

     

    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.EmpId)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.FirstName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.MiddleName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LastName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PhoneNo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Address)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.msg)
            </th>
            <th></th>
        </tr>
    
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.EmpId)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.FirstName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MiddleName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PhoneNo)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Address)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.msg)
                </td>
                <td>
                    <a class="lnkEdit" id='@item.EmpId'>Edit</a> | |
                    @Html.ActionLink("Details", "Details", new { id = item.EmpId }, new { @class = "lnkDetail" }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.EmpId }, new { @class = "lnkDelete" })
                </td>
            </tr>
        }
    
    </table>
    

     

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: