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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 42
    Comment on it

    While making use of different kind of operations sometimes you need to use Partial Views that will make the task easy.

     

     

    For doing that we need to invoke the partial view from our controller to assign data and making use of it.

     

     

      [HttpGet]
            public ActionResult _Edit(int id = 0)
            {
    
                EmpMod = new EmployeeModel();
                EmpMod.EmpId = id;
                EmpRep = new EmployeeRepository();
                EmpMod = EmpRep.EditDetails(EmpMod);
                return PartialView("_Edit", EmpMod);
    
            }

     

     

    We have made a partial view which gets the data id  from the index view and load all the details into it. So we are returning the partial view here to load the details of the employee.

     

    @model Modal_PopUp_Basic.Models.EmployeeModel
    
    @using (Html.BeginForm("SaveDetails","Home",new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
        {
            @Html.AntiForgeryToken()
    
    <h4>EmployeeModel</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        <div class="col-md-10">
            @Html.HiddenFor(model => model.EmpId, new { htmlAttributes = new { @class = "form-control" },id="hddnid" })
        </div>
    </div>
    
    <div class="form-group">
        @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" }, id = "txtfirstname" })
            @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
        </div>
    </div>
    
    <div class="form-group">
        @Html.LabelFor(model => model.MiddleName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.MiddleName, new { htmlAttributes = new { @class = "form-control", id = "txtmiddlename" } })
            @Html.ValidationMessageFor(model => model.MiddleName, "", new { @class = "text-danger" })
        </div>
    </div>
    
    <div class="form-group">
        @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" }, id = "txtlastname" })
            @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
        </div>
    </div>
    
    <div class="form-group">
        @Html.LabelFor(model => model.PhoneNo, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.PhoneNo, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.PhoneNo, "", new { @class = "text-danger" })
        </div>
    </div>
    
    <div class="form-group">
        @Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
        </div>
    </div>
    
    <div class="form-group">
        @Html.LabelFor(model => model.msg, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.msg, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.msg, "", new { @class = "text-danger" })
        </div>
    </div>
    
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Save" class="btn btn-default" />
    
            @Html.ActionLink("Back to List", "Index")
        </div>
    
    
    
    
    </div>
    
    
    
    
    
    
    
    }
    

     

    .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: