How to pass a model from view to controller using javascript in MVC 3

JS Code:



Funtion PassModel(){

var UserModel = {
                UserName: ‘Test’,
                PhoneNo: ‘00000000000’,
                Address: ‘ABCDEFGHI…’
};

var URL = "/UserController/UserAction?userdetails=" + UserModel;
                    $.get(URL, function (data) {
                        ShowResult(data.SaveResult);
                    });

}


HTML Code (View):



<input name="ClickedButton" type="button" id="btnSaveUser” value="Save New User"
                    onclick=" PassModel ()" class="commonbtn FR" />



C# Code (Controller):



public ActionResult UserAction (UserModel userdetails)
        {
            int SaveResult = DAL.SaveNewUser();
            return Json(new { SaveResult }, JsonRequestBehavior.AllowGet);
        }

Comments

Popular Posts

GREYCstoration Oil Paint plugin for Photoshop

Apple iPhone sending SMS automatically 00447786205094

SharePoint online hub navigation not updating for other users

Service Bus Gateway service stuck at Starting

RangeError: Maximum call stack size exceeded | Node JS | SPFX React