C# MVC和Razor的表单数据传递问题

C# MVC和Razor的表单数据传递问题,c#,forms,razor,C#,Forms,Razor,我正在使用RazorHTML并试图将数据发布到函数中。我可以得到部分数据提交和通过只是罚款,但其他部分我不能 @using (Html.BeginForm("Reply", "api/Reply", new { ID = Model.ID, UserName = Model.Username })) { <div id="mainArea" class="lightboxContent" style="display: block"> <div clas

我正在使用RazorHTML并试图将数据发布到函数中。我可以得到部分数据提交和通过只是罚款,但其他部分我不能

@using (Html.BeginForm("Reply", "api/Reply", new { ID = Model.ID, UserName = Model.Username }))
{
    <div id="mainArea" class="lightboxContent" style="display: block">
        <div class="lightboxText">
            <div class="responderTitleLeft">Select Profile:&nbsp;</div>
            <div class="responderFormFloat">
                <select name="profileSelector" class="select-style">
                    <option value="Select One" selected>Please Select Your Profile</option>
                    @foreach (var profile in Model.ProfileModels)
                    {
                        <option value="@profile.ProfileID">@profile.ScreenName</option>
                }
                </select>
            </div>
            <div class="responderActions">
                <div id="Reply" class="TwtiterReply">
                    <a href="javascript:void(0)">
                        <img src="/images/engage/actions/reply.png" onclick="toggle('ReplyArea')" title="Reply to message" />
                    </a>
                </div>
                <div id="ReplyArea" style="display: none;" class="responderForm">
                    <div class="responderTitle">Reply</div>
                    <textarea id="MessageEdit" name="Message" onkeyup="return characterCount(this)" onchange="postChange(this.id, 'messagePreview');" rows="4" cols="50" style="resize: none">@Model.Username</textarea>
                    <p id="counter"><strong><span id="charCount">140</span></strong> more characters available.</p>
                    <div class="lightboxButtonsBar">
                        <input type="button" onclick="toggle('mainArea')" tabindex="3" value="Reply" />
                        <input type="button" class="cancel" tabindex="4" value="Cancel" />
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="confirmArea" class="confirmationArea" style="display: none">
        <div class="warning">
            <p><strong>Warning:</strong></p>
        </div>
        <div class="warningMessage">
            <p>You are posting from @Model.ProfileModels with the message:</p>
            <div class="messagePreviewArea" data-form="Reply">
                <p>
                    <textarea id="messagePreview" readonly rows="4" cols="50" style="color: #ffffff; font-size: .9em; background-color: transparent; resize: none; border-color: #808080;"></textarea></p>
                <input type="submit" tabindex="3" value="Confirm" />
                <input type="button" onclick="toggle('mainArea')" tabindex="3" value="Cancel" />
            </div>
        </div>
    </div>
}

public UserProfile Reply(string ID, string UserName, FormCollection form)
        {
            var pSelector = form["profileSelector"];
            var message = form["Message"];



            ApiService msgserv = new ApiService();

            UserProfile up = UserProfile.GetFirst(new Guid(pSelector));

            messenger.Reply(up.key, UserName, ID, message);
            return up;
        }
@使用(Html.BeginForm(“Reply”,“api/Reply”,new{ID=Model.ID,UserName=Model.UserName}))
{
选择配置文件:
请选择您的个人资料
@foreach(Model.ProfileModels中的var配置文件)
{
@profile.ScreenName
}
回复
@Model.Username

140更多可用字符

警告:

您正在@Model.ProfileModels发布以下消息:

} 公共用户配置文件回复(字符串ID、字符串用户名、FormCollection表单) { var pSelector=form[“profileSelector”]; var消息=形式[“消息”]; ApiService msgserv=新的ApiService(); UserProfile up=UserProfile.GetFirst(新Guid(pSelector)); messenger.Reply(up.key、用户名、ID、消息); 返回; }
我希望从这个表单中得到什么(按照显示方式的顺序)ID和用户名(它们是由模型提供的,我没有问题。)

我遇到的问题是配置文件选择器和带有名称消息的文本区域


有人能告诉我如何将textarea和select放入表单中的正确方向吗?

select不向模型提供数据的原因是因为其
名称
属性未设置为与模型中的属性名称相对应。文本区域也是如此。一般来说,如果希望表单提交来填充这些属性,可以使用“强类型”帮助器方法,例如DropdownFor和CheckBoxFor。或者您可以手动将这些连接起来,尝试将select元素的名称设置为“SelectedProfile”,并将回复操作更改为:Reply(字符串ID、字符串用户名、字符串SelectedProfile、FormCollection表单)

要从textarea获取,请在视图上执行类似操作
@Html.textarea(“messagePreview”)但如果可以的话,我建议您在模型中保存内容