繁体   English   中英

从文本框中获取非模型信息,并将其通过Actionlink传递

[英]Taking non-model information from a text box and passing it through a Actionlink

因此,我试图建立一个包含问题,答案和评论的网站,就像stackoverflow一样。 现在,我正在尝试获取评论以使其正常工作。 我已经决定,我将尝试使用ActionLink将注释文本发送到controller 有什么方法可以在不调用模型字段的情况下执行此操作?

如果将输入内容放入<form>标签怎么办?

@using (Html.BeginForm("AddComent", "CommentsController"))
{
   @Html.TextBox("comment")
   <input type="submit" value="Post Your Comment" />
}

PS其他选项(我更喜欢)是使用JQuery发送Ajax Post调用: $.post("@Url.Action("$Action", "$Controller")", { $parameter: $data });

使用简单的表单提交,然后通过FormCollection获取提交的数据

[HttpPost] 
public ActionResult SubmitComment(FormCollection collection)
{
   string comment = collection["comment"];
}

和你的看法

@using (Html.BeginForm("SubmitComment", "CommentsController"))
{
   @Html.TextBox("comment")
   <input type="submit" value="submit" />
}

从长远来看,您最好将这些数据绑定到模型。 有关更多详细信息,请参见此链接: 是否有充分的理由使用FormCollection代替ViewModel?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM