Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 从多个表单中获取值_Asp.net_Asp.net Mvc - Fatal编程技术网

Asp.net 从多个表单中获取值

Asp.net 从多个表单中获取值,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我正在做一个ASP.NETMVC项目 我在一页中有多个表单 比如说 <form method="post" action="" id="Form1" name="Form1"> <textarea id="TextBox1" name="TextBox1" cols="8" rows="10"></textarea> </form> <form method="post" action="" id="Form2" name="For

我正在做一个ASP.NETMVC项目

我在一页中有多个表单

比如说

<form method="post" action="" id="Form1" name="Form1">
    <textarea id="TextBox1" name="TextBox1" cols="8" rows="10"></textarea>
</form>

<form method="post" action="" id="Form2" name="Form2">
   <textarea id="TextBox2" name="TextBox2" cols="8" rows="10"></textarea>
</form>
上次更新

我想我找到了解决办法


我只需要使用一个ajax表单,并在表单中放置一个提交按钮…

它会显示提交按钮所在的位置。无论按下哪个表单的提交按钮,表单都将发布到相应的操作。链接可能会帮助你

你需要这样做

<script>
function formsubmit()
{
 document.form1.action="Page Name here you want to go that
page";
 document.form1.submit();
}
</script>

<form name="form1" method="post">
<input type= text onblur="formsubmit();">
</form>

函数formsubmit()
{
document.form1.action=“页面名称在这里,您想继续吗
页面”;
文件。表格1。提交();
}

您将获得您提交的任何表单的值,但代码中的任何地方都没有“提交”按钮。

实际上,我正在使用ajax调用将用户的评论发布到数据库中。所以根本没有提交按钮。。。我只是无法从文本区域捕获值。。。有什么帮助吗?我需要使用Ajax表单而不是常规表单吗?
        [HttpPost]
    public ActionResult SubmitThisReply(int ParentID, int ArticleID, FormCollection form)
    {
        //FormCollection form = new FormCollection();
        int UserID = Convert.ToInt16(Session["UserID"].ToString());
        string contentName ="txtReplyComment-"+ParentID.ToString();
        string content = form[contentName];

        QA replyQuestion = new QA();
        replyQuestion.ArticleID = ArticleID;
        replyQuestion.UserID = UserID;
        replyQuestion.ParentID = ParentID;
        replyQuestion.Content = "1";

        qaFunction.ReplyQA(replyQuestion);

        var allQA = bio.QAListByArticleID(ArticleID).ToList(); //Return Type: QAViews
        var firstLevelQA = allQA.Where(c => c.ParentID == null);

        ViewData["AllQA"] = allQA;
        ViewData["FirstLevelQA"] = firstLevelQA;


        if (!Request.IsAjaxRequest())
        {
            return RedirectToAction("ArticleDetail", "Home", new { articleID = ArticleID });
        }

        return PartialView("QAControl", ViewData["FirstLevelQA"]);
    }
}
<script>
function formsubmit()
{
 document.form1.action="Page Name here you want to go that
page";
 document.form1.submit();
}
</script>

<form name="form1" method="post">
<input type= text onblur="formsubmit();">
</form>