通过JQuery(MVC3)发布到控制器 [英] Posting to controller via JQuery (MVC3)

查看:59
本文介绍了通过JQuery(MVC3)发布到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早安,

我对使用jquery真的很陌生,并有以下问题:

我的cshtml页面:

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



我想要做的就是调整我的cshtml页面,以使用JQUERY通过GameUser对象传递到contoller中的create动作.

有人可以帮助我实现这一目标.我正在学习并且如果我看到自己的代码正在调整,它会更容易.

谢谢



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

推荐答案



在表单声明中,您应该声明后操作,即Html.BeginForm("ActionName","Controller Name",FormMethod.Post).然后,您可以通过输入提交按钮或Jquery提交来进行提交.例如,
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();
(''#element'').submit();


回发不总是提交内容的答案MVC3中的数据.我们可以使用查询Post和Get方法来异步执行操作.
希望对您有帮助.
在MVC3中使用JQuery发布数据
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


这篇关于通过JQuery(MVC3)发布到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆