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";
}

<h2>Create</h2>

<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()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>GameUser</legend>

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

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

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


        <div class="editor-field">
            @Html.Hidden("LastActiveDate")

        </div>

 
        <p>
            
            <input type="submit" value="Submit" />
        </p>
    </fieldset>
}


[HttpPost]
 public ActionResult Create(GameUser gameuser)
 {
     if (ModelState.IsValid)
     {
         db.GameUsers.AddObject(gameuser);
         db.SaveChanges();
         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
Posted
Updated 16-Jul-12 11:44am
v2

Hi,

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
 
Comments
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