简体   繁体   English

无法从表单获取数据到模型 MVC

[英]Trouble getting Data from a form to the model MVC

The Code From my View:我认为的代码:

@using (Html.BeginForm())
{
    @Html.TextBoxFor(Model => Model.strlist)
    <input type="submit" value="Send" />
}

The Code From my Model:我的模型中的代码:

public class CommentClass
{
    public ArrayList strlist = new ArrayList();
}

The Code From my Controller:来自我的控制器的代码:

[HttpPost]
public ActionResult SendChat()
{
    return View("~/Views/Room/Chat.cshtml");
}

I have looked and I can't find anything simple on how to get my data from that textbox on my form to populate the list.我已经看过了,但找不到任何关于如何从表单上的文本框中获取数据以填充列表的简单信息。 Any help would be much appreciated.任何帮助将非常感激。

Warning, This is just some sudoCode警告,这只是一些 sudoCode

Based on my and Adyson's comments, you need to do something like:根据我和 Adyson 的评论,您需要执行以下操作:

[HttpPost]
public ActionResult SendChat(CommentClass comment) 
{
    comment.strList.Add( <insert your new comment here> );
    return View("~/Views/Room/Chat.cshtml");
}

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

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