0

I work with ASP.NET MVC 4 and I have an issue with bootstrap modal. I have a modal with a form containing 4 DropDownList (in a partial view), when I submit the form the action check in the database if the reference exist.

I want to display an alert in the modal if the reference doesn't exist without leaving the modal, please tell me if this is possible and how ?

This is a part of my view

@using (Html.BeginForm("AfficherBobine", "Home"))
{
<div class="modal fade" id="ChoisirBobine" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="container-fluid">
                    <section class="row">
                        @Html.Partial("PartialFormBobine")
                    </section>
                    <section class="row">

                    </section>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                <button type="submit" class="btn btn-default">Envoyer</button>
            </div>
        </div>
    </div>
</div>
}

And this is the code of the action :

[HttpPost]
        public ActionResult AfficherBobine(string annee, string semaine, string montage, string numero)
        {
            string arg = annee + semaine + montage + numero;

            IDal dal = new Dal();
            //this is the code to check if the reference exist

            SortedList arg_Params = new SortedList();
            arg_Params.Add("NUM_BOBINE", arg);
            List<CheckIdentite> Bobine = dal.RetourneIdentite(ref arg_Params);

            if (Bobine.Count != 0)
            {
                return RedirectToAction("Index", new { id = arg });
            }
            else
            {
                //Here the code to show an alert ("Wrong selection")
            }
        }

Thanks for your attention

Ixigrec
  • 13
  • 4
  • Your problem is your doing a post, so what you are going to return is going to refresh the page, losing the modal. Have you tried using Ajax to submit your form and then using that as the result? – Jamie Rees Jul 02 '15 at 08:17
  • Agree to Jamie Rees. Use ajax form or post your data with jquery. http://stackoverflow.com/questions/17095443/how-to-use-simple-ajax-beginform-in-asp-net-mvc-4 – Kadir Jul 02 '15 at 08:31

0 Answers0