Asp.Net MVC partial view form post replaces entire page

309
May 30, 2017, at 05:34 AM

I am using Asp.Net MVC and I have got a problem with a form. I have got a partial view inside a view which has go a form inside.

It looks like this:

Inside Main.cshtml

<div id="Artikel" hidden>
    @Html.Action("_Artikel", Model);
</div>

This renders the partial view.

Controller of the partial view

public ActionResult _Artikel()
{
    return PartialView()
}

All of that works fine but when I fire my Ajax.BeginForm(...) it replaces the whole view but not just the Arikel Div.

Inside the partial view

@using (Ajax.BeginForm("_Artikel", "Home", new AjaxOptions { HttpMethod = "post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "Artikel" }))
{
    ...
}

I read many articles that there is aproblem with jQuery.Unobtrusive.Ajax not supported in the latest versions of jQuery.

But I really can't figure out why it always takes up the entire page. Can someone help me? If you need more code ask for it.

Answer 1

Make sure you put

<add key="UnobtrusiveJavaScriptEnabled" value="true" />

in the appSettings of your web.config file.

Rent Charter Buses Company
READ ALSO
Get values of dynamically created input elements

Get values of dynamically created input elements

I have created dynamic input elements using the JavaScript below:

314
jQuery Fixed Header Table doesn&#39;t work with Angular2 ngFor

jQuery Fixed Header Table doesn't work with Angular2 ngFor

I need to create table in Angular2 with fixed header and left (or right) column scrollable vertically and horizontally (both bars should be visibile all the time) and auto width columnsI've tried to do this without jQuery but eventually I had to use it

423
Ajax request piling up on consecutive actions

Ajax request piling up on consecutive actions

Context: I'm implementing a form in modalBoth form opening and form submitting are ajax requests

297