我在做一個ASP.NET MVC項目。從多個表格獲取價值
我在一個頁面中有多個表單。
例如
<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>
在控制器中,我想從TextBox2中的價值,我該怎麼辦?
如果我使用FormCollection form = new FormCollection(); 我得到了哪種形式?
非常感謝
更新的代碼
這裏是鏈接,當它的用戶點擊,文本框的值將被提交。
<%= Ajax.ActionLink("Submit Reply", "SubmitThisReply", "Home",
new { ParentID = item.QAID, ArticleID = item.ArticleID },
new AjaxOptions { UpdateTargetId = "QAContents", OnSuccess = hiddenDivName },
new { @class = "linkButton" })%>
這裏是控制器
[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"]);
}
}
最後更新
嗯,我想我找到了解決方案的代碼。
我只需要使用AJAX的形式,並把該表單內提交按鈕...
你的提交按鈕在哪裏 – Tassadaque