1

I have an asp.net mvc application. I need to reload a partial with ajax post. Here is my cshtml code inside main view:

<button data-url='@Url.Action("GetErrors", "Interface", new { servers = "S97EGESRV01" })'
            class="js-reload-details">
        Reload
    </button>
    <div id="errorListDiv">

        @Html.Partial("~/Views/Partials/_ErrorListPartial.cshtml", Model.Errors)
    </div>

javascript:

$('.js-reload-details').on('click', function (evt) {
    evt.preventDefault();
    evt.stopPropagation();

    var errorListDiv = $('#errorListDiv');
    var url = $(this).data("Interface/GetErrors?servers=S97EGESRV01");

    $.get(url, function (data) {
        errorListDiv.replaceWith(data);
    });
});

C#:

public ActionResult HatalariGetir(string servers= "All", InterfaceViewModel interfaceModel = null)
{
if (interfaceModel == null) {
     interfaceModel = new InterfaceViewModel();
}
// Some database processes
List<ErrorViewModel> modelList = new List<ErrorViewModel>();
// Populating modelList
interfaceModel.Errors = modelList;
return View("~/Views/Partials/_ErrorListPartial.cshtml", interfaceModel.Errors);
}

But the thing is when I click "Reload" button, whole page is loaded inside errorListDiv. Not just partial view. What am I doing wrong?

EDIT: I tried this:

return PartialView("~/Views/Partials/_ErrorListPartial.cshtml", interfaceModel.Errors);

Unfortunately result is same.

4
  • possible duplicate of asp.net MVC partial view controller action Commented Jun 16, 2014 at 20:41
  • Why do you have to pass the path to the view? Commented Jun 16, 2014 at 20:45
  • Actually I don't have to. But otherwise result is same. Commented Jun 16, 2014 at 20:48
  • In your view put {Layout = null;} Commented Jun 16, 2014 at 21:17

2 Answers 2

2

Try adding this to your view file.

@{
    Layout = null;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Actually your partial view is not working like partial view, it is rendering with master layout as a full view, so what you need is to explicitly tell in view that do not use any master layout by adding this line in top of view:

@{


Layout = null;

}

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.