Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a popup on click of login button and have also used a partial view
but the form appears fine but after clicking on login button that is on
popup it dosent go to the controler or anywhere so pls see this code and tell me how to solve that thanks!!


CSHTML CODE:-

HTML
@model MVCApplication10.Models.LoginModel
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery-ui-1.8.24.js"></script>
<link href="~/Content/themes/base/jquery.ui.core.css" rel="stylesheet" />
<link href="~/Content/themes/base/jquery.ui.dialog.css" rel="stylesheet" />
 @Styles.Render("~/Content/themes/base/css", "~/Content/css")
<script type="text/javascript">
    var $J = jQuery.noConflict();

    $J(function () {
        $J('#demo').dialog({
            autoOpen: false,
            width: 400,
            title: "Login",
            resizable:false

        });
        $J('#pop').click(function () {
            $J('#demo').dialog('open');
        });
    });
</script>
<style type="text/css">
  @Styles.Render("~/Content/themes/base/css", "~/Content/css")
</style>

@{
    ViewBag.Title = "Login";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Login</h2>

<input type="button" id="pop" value="New" />
@*<div id="demo" >*@
        @using (Html.BeginForm())
        {
            @Html.AntiForgeryToken()
   

            <fieldset>
                <legend></legend>

                <div class="editor-label">
                    @Html.LabelFor(model => model.Mobile)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Mobile)
                    @Html.ValidationMessageFor(model => model.Mobile)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(model => model.Password)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Password)
                    @Html.ValidationMessageFor(model => model.Password)
                </div>

                <p>
                    <input type="submit" value="Login" />
                    @Html.ValidationSummary(true)
                </p>
            </fieldset>
        }
@*</div>*@
<div>



MODEL CLASS :-


C#
[Required(ErrorMessage = "Enter Mobile Number")]
       [Display(Name = "Mobile")]
       public decimal Mobile { get; set; }

  [Required(ErrorMessage = "Enter Password")]
       [Display(Name = "Password")]
       [DataType(DataType.Password)]
       public string Password { get; set; }



C#
public bool IsValid(decimal Mobile,string Password)
       {
           var query = (from c in db.CustomerMasters where c.Mobile == Mobile && c.Password == Password && c.IsDeleted == false select c).SingleOrDefault();
           if(query!=null)
           {
               return true;
           }
           else
           {
               return false;
           }
       }




Controller Class :-

SQL
[HttpGet]
        public ActionResult Login()
        {

            return View();
        }
        [HttpPost]
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.IsValid(model.Mobile, model.Password))
                {
                    //FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
                    return RedirectToAction("About", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Invalide Mobile Number Or Password...!!!");
                }
            }
            return View(model);
        }
Posted

1 solution

Change following codes

JavaScript
$J(function () {
        $J('#demo').dialog({
            autoOpen: false,
            width: 400,
            title: "Login",
            resizable:false,
            buttons: {
                "Login": function() {
                        $("#formID").submit(); //formID-id of your form.
            }
        });
        $J('#pop').click(function () {
            $J('#demo').dialog('open');
        });
    });


then change Html.BeginForm() as below
HTML
Html.BeginForm("ActionName","Controller")

where action name -you HttpPost fucntion.

When you click the "login" button that appears on the dialog box, it will call the function you have specified.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900