2个形式的2个文本框,名称相同

时间:2011-06-16 11:10:03

标签: asp.net asp.net-mvc

我在表单上有两个类似的表单块:

        <form action="/2/All/Home/SubIdeaComment?SubIdeaID=5576&amp;referrerUrl=http%3A%2F%2Flocalhost%3A1261%2F2%2FAll%2FHome%2FIdea%2F5575%3FreferrerUrl%3Dhttp%253A%252F%252Flocalhost%253A1261%252F2" method="post">



        <textarea id="SubComment" name="SubComment" style="width: 80%"></textarea>

        <br />

        <input type="submit" class="InputBtn" value="Reply" />

        <input type="reset" class="InputBtn" onclick="ShowHideReply($('#divSubIdeaReply5576'), $('#subIdeaButtons5576'))"

            value="Cancel" />

        <br />

        <br />

        </form>

        <form action="/2/All/Home/SubIdeaComment?SubIdeaID=5577&amp;referrerUrl=http%3A%2F%2Flocalhost%3A1261%2F2%2FAll%2FHome%2FIdea%2F5575%3FreferrerUrl%3Dhttp%253A%252F%252Flocalhost%253A1261%252F2" method="post">



        <textarea id="SubComment" name="SubComment" style="width: 80%"></textarea>

        <br />

        <input type="submit" class="InputBtn" value="Reply" />

        <input type="reset" class="InputBtn" onclick="ShowHideReply($('#divSubIdeaReply5577'), $('#subIdeaButtons5577'))"

            value="Cancel" />

        <br />

        <br />

        </form>

我需要调用相同的控制器方法(MVC项目):

    [AcceptVerbs(HttpVerbs.Post)]
    [ValidateInput(false)]
    public ActionResult SubIdeaComment(int SubIdeaID, string SubComment, string referrerUrl)
    {
        if (User.Identity.IsAuthenticated && !String.IsNullOrWhiteSpace(SubComment))
            _repository.AddComment(User.Identity.Name, SubIdeaID, null, SubComment);
        return Redirect(referrerUrl);
    }

但是当第一个表单提交时 - 我将SubComment设为空。据我了解,原因是2个字段具有相同的名称。但是有不同的形式....如何正确地做到这一点?

1 个答案:

答案 0 :(得分:1)

正如您已经正确假设的那样,id - 属性必须是唯一的。我不知道这些表单是如何在您的应用中生成的,但是使用templates可能会帮助您。