在 MVC 中,控制器可以直接与视图对话吗?
我正在尝试理解 MVC。
假设在视图上我有一个复选框,我们将其称为“checkBox1”...
在我的控制器中,我可以直接访问此复选框吗?
我可以去吗: checkBox1.Checked = true
??
I'm trying to understand MVC.
Let's say on the View I have a checkbox, we'll call it 'checkBox1'...
In my Controller, can I access this checkbox directly?
Can I go:
checkBox1.Checked = true
??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
控制器无法直接访问视图的元素,因为它没有有关视图的信息。控制器只能充当控制点来调节视图和模型之间的数据。但是,您可以从控制器操作视图,例如加载特定视图模板或将一段代码(在 xhr 请求的情况下)渲染到输出。但是一旦它渲染出来,它就不会拥有有关视图各个元素的任何信息。
看看这个
http://www.enode.com/x/markup/教程/mvc.html
A controller cannot directly access the elements of a view as it has no information about it. A controller can only act as a point of control to regulate data between the views and models. However you can manipulate the views from the controller like loading a specific view template or rendering a chunk of code ( in case of xhr request) to the output. But once it renders that it will not have any information about the individual elements of the view.
Take a look at this
http://www.enode.com/x/markup/tutorial/mvc.html
不。控制器处理发送到视图和从视图发送的数据(模型),并故意与视图的细节分开。
我建议花一些时间阅读 ASP.NET MVC 的基础知识,并在 ASP.NET MVC 站点上学习一些教程
阅读此处了解有关处理复选框的详细信息...
MVC3.0 中的复选框列表
No. The controller deals with the data (model) sent to and from the view and is deliberately separated from the details of the View.
I suggest spending some time reading up on the basics of ASP.NET MVC and doing some tutorials on the ASP.NET MVC site
Read here for details on handling checkboxes...
CheckboxList in MVC3.0