在 MVC 中,控制器可以直接与视图对话吗?

发布于 2024-12-01 17:46:32 字数 144 浏览 2 评论 0原文

我正在尝试理解 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 技术交流群。

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

发布评论

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

评论(2

心安伴我暖 2024-12-08 17:46:32

控制器无法直接访问视图的元素,因为它没有有关视图的信息。控制器只能充当控制点来调节视图和模型之间的数据。但是,您可以从控制器操作视图,例如加载特定视图模板或将一段代码(在 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

绅刃 2024-12-08 17:46:32

不。控制器处理发送到视图和从视图发送的数据(模型),并故意与视图的细节分开。

我建议花一些时间阅读 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

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