1

I'm trying to Update a part of my view, using Ajax and Partial view, but I got some trouble : This my controller :

 [HttpPost]
        public ActionResult Index(StatModel model)
        {
            if (ModelState.IsValid)
            {

                switch (model.SelectedStat)
                {
                    case "agR" : 
                        List<agR> agentr = nbrAGbyR(model.SelectedItemsRegion.ToList());
                        return PartialView("_agByR", agentr);

                    case "demandeR":
                        List<demandeR> demander = nbrDMbyR(model.SelectedItemsRegion.ToList());
                        return PartialView("_dmByR", demander);
                    ... Other case option ....

                }
            }
            ..
            return PartialView();
        } 

This is my Index.cshtml View :

@model pfebs0.Models.StatModel
...
<div class="row">
  <div class="col-md-6">
    <h2>Statistique Par region</h2>

@using (Ajax.BeginForm("Index", new AjaxOptions
                                        {
                                            UpdateTargetId = "result",
                                            InsertionMode = InsertionMode.InsertAfter,
                                            HttpMethod = "POST"
                                        }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

       @Html.ListBoxFor(m=>m.SelectedItemsRegion, (ViewBag.REGIONID as SelectList))

       @Html.DropDownListFor(m=> m.SelectedStat, Model.statList) 
        <p>
            <input type="submit" value="Create" />
        </p>
}
  ...
    <div class="col-md-10">
        <h2>Resultat</h2>
        <div id="result"></div>
    </div>
    ...

And this an Example Of my partialView :

@model List<pfebs0.Models.agR>
@using GridMvc.Html

    <h3 id="agR">Statistique Agent generaux par region</h3>

       @Html.Grid(Model).Named("agR").Columns(columns =>
                        {
                            columns.Add(model => model.nbr)
                                .Sortable(false)
                                .Titled("Nombre des Agent's");
                            columns.Add(model => model.regionName)
                                .Sortable(true)
                                .Titled("Nom du region");                           


                        }).WithPaging(10)

When I click on submit button nothing happend, what's the problem here?

1 Answer 1

2

Forgive me for just posting a link to another answer but this may be what you are looking for: Using Ajax.BeginForm with ASP.NET MVC 3 Razor.

Personally, I have never used Ajax.BeginForm and always used jquery for my ajaxiness. That answer does show you how to do it as you may be missing the unobtrusive ajax js script declaration but I do not know with your truncated code.

Hope that helps though!

Sign up to request clarification or add additional context in comments.

2 Comments

Trying to follow the link I got same result nothing happend when I click on submit button
To alleviate the aggravation, Personally, I would convert it to use jquery as the ajax functionality. At the bottom of the answer, it shows how to change it.

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.