相关疑难解决方法(0)

如何在提交前向表单添加其他字段?

有没有办法使用javascript和JQuery添加一些使用POST从HTTP表单发送的其他字段?

我的意思是:

<form action="somewhere" method="POST" id="form">
  <input type="submit" name="submit" value="Send" />
</form>

<script type="text/javascript">
  $("#form").submit( function(eventObj) {
    // I want to add a field "field" with value "value" here
    // to the POST data

    return true;
  });
</script>
Run Code Online (Sandbox Code Playgroud)

html forms jquery post field

95
推荐指数
6
解决办法
17万
查看次数

ASP.NET-MVC中Form Form上的FormCollection为空

我使用过去经常使用的方法发布一个非常简单的表单.显示我的代码可能更容易,而不是输入冗长的解释.这是HTML:

<% Html.BeginForm("CreateMarketingType", "ListMaintenance"); %>
    <div id="ListMaintenanceContainer">
        <table>
            <tr>
                <th>Marketing Type Id</th>
                <th>Marketing Type Name</th>
            </tr>                    
                <%foreach (MarketingType marketingType in ViewData.Model.MarketingTypes) %>
                <%{ %>
                    <tr>
                        <td><%= marketingType.MarketingTypeId.ToString() %></td>
                        <td><%= marketingType.MarketingTypeName %></td>
                    </tr>
                <%} %>
        </table>
        <div>
            <fieldset id="fsSaveNewMarketingType">
                <legend>Add New Marketing Type</legend>
                <label for="txtNewMarketingTypeName">New Marketing Type Name:</label>
                <input type="text" id="txtNewMarketingTypeName" />
                <input type="submit" value="Save" id="CreateMarketingType" />
            </fieldset>
        </div>                    
    </div>
<% Html.EndForm();%>
Run Code Online (Sandbox Code Playgroud)

这是控制器代码:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateMarketingType(FormCollection form)
{
    string newMarketingTypeName = Request.Form["txtNewMarketingTypeName"].ToString();

    MarketingType newMarketingType = new MarketingType() { MarketingTypeName = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc

30
推荐指数
1
解决办法
3万
查看次数

使用ajax提交表单

我正在开发一个应用程序(我的大学的一种社交网络).我需要添加注释(在特定数据库中插入一行).为此,我在html页面中有一个包含各种字段的HTML表单.在提交时我不使用表单的操作,但我在提交表单之前使用自定义javascript函数来详细说明一些数据.

function sendMyComment() {

    var oForm = document.forms['addComment'];
    var input_video_id = document.createElement("input");
    var input_video_time = document.createElement("input");

    input_video_id.setAttribute("type", "hidden");
    input_video_id.setAttribute("name", "video_id");
    input_video_id.setAttribute("id", "video_id");
    input_video_id.setAttribute("value", document.getElementById('video_id').innerHTML);

    input_video_time.setAttribute("type", "hidden");
    input_video_time.setAttribute("name", "video_time");
    input_video_time.setAttribute("id", "video_time");
    input_video_time.setAttribute("value", document.getElementById('time').innerHTML);

    oForm.appendChild(input_video_id);
    oForm.appendChild(input_video_time);

    document.forms['addComment'].submit();
}
Run Code Online (Sandbox Code Playgroud)

最后一行将表单提交到正确的页面.它工作正常.但我想使用ajax提交表单,我不知道如何做到这一点,因为我不知道如何捕获表单输入值.有人可以帮帮我吗?

html javascript ajax jquery

17
推荐指数
5
解决办法
9万
查看次数

如何在我的JQUERY提交中添加其他数据?

在我的剃刀视图中,我正在使用Html.BeginForm.在其中我有两个元素,当我设置clic时,应该提交表单但我需要添加一个额外的字符串参数.

@using (Html.BeginForm("Index", "Quiz", FormMethod.Post, new { id = "form" }))
{
    ...
}

    [HttpPost]
    public ActionResult Index(string parameter, QuizCompletedViewModel q)  //FormCollection f)
    {            
        ...
        if (button.Equals("d"))
        {
            ...
            return RedirectToAction("ShowResults", new { testId = Quiz.QuizId, answeredTest = answeredId });
        }
        else
        {
            ...
            return RedirectToAction("Index", "Dashboard");
        }
    }
Run Code Online (Sandbox Code Playgroud)

因此,在我使用的jquery函数中$("#element").submit(),参数parameter始终为null(这是正常的).如何添加其他数据以parameter使用JQUERY?

注意:我没有使用AJAX.

c# asp.net-mvc jquery jquery-ui asp.net-mvc-4

2
推荐指数
2
解决办法
9445
查看次数

标签 统计

jquery ×3

asp.net-mvc ×2

c# ×2

html ×2

ajax ×1

asp.net ×1

asp.net-mvc-4 ×1

field ×1

forms ×1

javascript ×1

jquery-ui ×1

post ×1