路线价值保持不变
在我的 .cshtml 中,我正在绘制一些数据。然后我有一个回复文本框和一个按钮,供人们回复客户服务线程。
@using (Html.BeginForm("Update", "CustomerServiceMessage", FormMethod.Post, new { id = 0 }))
...
}
当我提交时,当它点击我的更新操作方法时,我没有得到 0,我得到了我在回复框上方绘制的父服务消息的 id。所以它就像一个电子邮件/论坛线程,但即使我硬编码 = 0,Update 方法也会获取我在屏幕上绘制(渲染)的父消息的 ID。
不明白为什么。
In my .cshtml, I'm painting some data. Then I have a repy textbox and a button for people to reply to a customer service thread.
@using (Html.BeginForm("Update", "CustomerServiceMessage", FormMethod.Post, new { id = 0 }))
...
}
When I submit, I don't get 0 when it hits my Update actionmethod, I get the id of the parent Service message I painted above the reply box. So it's like an email/forum thread but even though I hard code the = 0 the Update method is getting an Id of the parent message that I painted on the screen (rendered).
Can't figure out why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正常的,你永远不会将此 id 发送到你的服务器。您刚刚使用了
Html.BeginForm< 的错误的重载 /code> helper:
最终得到以下标记(假设默认路由):
看到问题了吗?
这是正确的重载:
生成(假设默认路由):
现在,您将在相应的控制器操作中获取您的
id=0
。顺便说一句,您可以使用 C# 来使代码更具可读性并避免此类错误4.0 命名参数:
That's normal, you never send this id to your server. You just used the wrong overload of the
Html.BeginForm
helper:and you ended up with the following markup (assuming default routes):
See the problem?
And here's the correct overload:
which generates (assuming default routes):
Now, you will get your
id=0
inside the corresponding controller action.By the way you could make your code more readable and avoid this kind of mistakes by using C# 4.0 named parameters: