Error in AjaxOption () ASP.NET MVC 5

0

I'm a novice and this is practicing the use of AJAX in ASP.NET MVC.

I have a partial view in which I want to have a form with Ajax.BeginForm () in which I can enter a number and through Ajax, when I press it, I multiply x2 and the result shows it in a span.

@{
    ViewBag.Title = "Contact";
    Layout = "~/Views/Shared/Lockout.cshtml";
}

<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

@using (Ajax.BeginForm("DuplicarCantidad_Ajax", "Home",
        new AjaxOption()
        {
            HttpMethod = "POST",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "resultado-ajax"
        }))
    {
        <span>Cantidad a duplicar:</span><input type="number" name="cantidadCS" />
        <input class="btn btn-primary" type="submit" value="Calcular" name="btn-cantidad-ajax" />
        <div>Resultado: <span id="resultado-ajax"></span></div>
    }
)

I'm getting an AjaxOption () error. It tells me that a using directive or an assembly reference is missing.

I have already tested using the System.Web.Mvc.Ajax, but the error is not yet removed.

What can I be missing?

Thanks

    
asked by Mateo Castaño Tobon 22.05.2018 в 20:50
source

1 answer

0

the object to instantiate is called AjaxOptions no AjaxOption

@{
    ViewBag.Title = "Contact";
    Layout = "~/Views/Shared/Lockout.cshtml";
}

<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

@using (Ajax.BeginForm("DuplicarCantidad_Ajax", "Home",
        new AjaxOptions()
        {
            HttpMethod = "POST",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "resultado-ajax"
        }))
    {
        <span>Cantidad a duplicar:</span><input type="number" name="cantidadCS" />
        <input class="btn btn-primary" type="submit" value="Calcular" name="btn-cantidad-ajax" />
        <div>Resultado: <span id="resultado-ajax"></span></div>
    }
)
    
answered by 23.05.2018 / 12:59
source