Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good Day,

I am really new to using jquery and have the following question:

My cshtml page:
@model Gaming.Models.GameUser

    ViewBag.Title = "Create New User";


<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {

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

        <div class="editor-label">
            @Html.LabelFor(model => model.Info)
        <div class="editor-label">
            @Html.TextAreaFor(model => model.Info, new { cols = 90, @rows = 20 })
            @Html.ValidationMessageFor(model => model.Info)

        <div class="editor-label">
            @Html.LabelFor(model => model.Category_ID, "Category")
        <div class="editor-field">
            @Html.ValidationMessageFor(model => model.Category_ID)

        <div class="editor-field">


            <input type="submit" value="Submit" />

 public ActionResult Create(GameUser gameuser)
     if (ModelState.IsValid)
         return RedirectToAction("Index");

     return View(gameuser);

All I want to to is to adjust my cshtml page to post to the create action in my contoller, passing through the GameUser Object using JQUERY.

Can someone please assist me to achieve this. Im learning and its easier if i see my own code being adjusted.

Thank you
Updated 16-Jul-12 11:44am


in your form declaration you should state the post action i.e. Html.BeginForm("ActionName","Controller Name", FormMethod.Post). You can then cause a submit via your input submit button or Jquery submit. i.e. $('#element').submit();
Share this answer
db7uk 16-Jul-12 18:21pm    
I guess the question is: Why do you want to execute the submit using JQuery when you have a button? What is the overall goal?
a post back shouldn't always be a answer for submission of data in MVC3. We can use query Post and Get methods to do operations asynchronously.
Hope this will help you.
Post Data Using JQuery in MVC3
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