2

i am bit new in asp.net mvc. i am facing problem for very basic things that my Partial view not rendering. here is the details

i have a main page and one partial view

main page action look like

public ActionResult Index()
{
    return View();
}

main index view look like

@model Testing.Models.Employee

@{
    ViewBag.Title = "Home Page";
}

<div class="row">

</div>

<div class="row">
    <div id="formsIndex">
    @{
        Html.Partial("_TestForm");
    }
    </div>
</div>

@section scripts {
       <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
}

here i am showing a partial view like this way Html.Partial("_TestForm"); but no UI comes for partial view.

partial view code look like

@model Testing.Models.Employee

@using (Ajax.BeginForm("Index", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "formsIndex" }))
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">

        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.City, "", 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">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-primary" />
            </div>
        </div>
    </div>
}

when i pass model to partial view this way Html.Partial("_TestForm", Model); then also no UI comes.

please tell me where i made the mistake ?

3 Answers 3

2

use in method return PartialView() and try this

@Html.Partial("_TestForm");
Sign up to request clarification or add additional context in comments.

Comments

2

Using Html.Partial inside a @{ ... } block will just call the method and throw the result away.

You should call it outside of a @{ ... } block, prefixed with @, and remember to pass in the model:

<div id="formsIndex">
@Html.Partial("_TestForm", Model);
</div>

Comments

1

Render like this

@Html.Action("_Partialview", "controllerName")

also create action methode of partial view

public ActionResult _Partialview
{
    Employee _objModel= new Employee ()
    return PartialView(_objModel);
}

Comments

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.