Html.BeginForm 部分用于不同的控制器

发布于 2024-09-07 09:41:45 字数 582 浏览 1 评论 0原文

我有以下代码:

<% using (Html.BeginForm("AddComment", "Comments", FormMethod.Post)) { %>
<div id="New_Comment">
<textarea name="newComment" id="newComment">Add comments</textarea>
<input type="submit" value="Add" />
<div><span class="text_grey">Attach:</span><a href="#" class="link_text_grey">File</a> <a href="#" class="link_text_grey">Link</a></div>
</div>
<%} %>

这是由 MyPage 控制器呈现的部分代码。由于某种原因,表单上的操作显示为空白,如果我引用 MyPage 控制器上的方法,它可以正常工作,我想要做的是使用我的表单指向不同的控制器。

I have the following code:

<% using (Html.BeginForm("AddComment", "Comments", FormMethod.Post)) { %>
<div id="New_Comment">
<textarea name="newComment" id="newComment">Add comments</textarea>
<input type="submit" value="Add" />
<div><span class="text_grey">Attach:</span><a href="#" class="link_text_grey">File</a> <a href="#" class="link_text_grey">Link</a></div>
</div>
<%} %>

This is in a partial rendered by the MyPage controller. For some reason the action on the form comes out blank, if I reference a method on the MyPage controller it works fine what I want to do is point to a different controller with my form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

メ斷腸人バ 2024-09-14 09:41:46

为了解决这个问题,我简单地添加了一个区域路由值,如下所示:

new { area = "" }

用空字符串将路由引导到默认区域。

To solve this issue I simple added in an area route value like so:

new { area = "" }

With the empty string directing the route to the default area.

眼眸里的那抹悲凉 2024-09-14 09:41:46

1) 您的“评论”操作是否被标记为 POST 操作?

2)也

尝试只是做:

<% Html.BeginForm("AddComment", "Comments"); %>

// Html and script

<% Html.EndForm(); %>

我知道你所拥有的和我建议的之间不应该有区别,但值得一试。

1) Is your "Comments" action marked as being a POST action?

2) Also

Try just doing:

<% Html.BeginForm("AddComment", "Comments"); %>

// Html and script

<% Html.EndForm(); %>

I know that there shouldn't be difference between what you have and what I suggest, but it's worth a try.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文