.Net MVC 4 视图引擎 WebForm

发布于 2024-12-11 02:12:04 字数 580 浏览 9 评论 0原文

在我看来,这是一个非常有趣的问题。 我有一个使用 WebForm 视图引擎的强类型视图,我不知道更改为 razor 是否可以解决我的问题。

问题: 我有一个包含汽车列表的视图,因此类型为 IList。 我有一个弹出按钮“创建一辆新车”,弹出窗口是一个隐藏的表单,您可以调用 jQuery UI 命令$('formName').dialog()< /code> 弹出它,此表单具有可能的新车的属性,因此可能是一个具有强类型 Car 的新视图。填写表单后,应使用新车填充数据库,并应使用 Ajax 刷新汽车列表。 主要问题是我无法同时使用 HTML Helpers 来 IListCar

简单地说: 该视图的强类型是什么?是否可以定义两个视图,另一个视图使用弹出窗口进行调用?将其更改为 Razor 可以解决我的问题吗?

最诚挚的问候,

Tito Morais

This is a quite interesting question, in my opinion.
I have a strongly typed view using the WebForm view Engine, I don't know if changing to razor would solve my problem.

PROBLEM:
I have one view with a list of cars, so of type IList <Car>.
And I have a button "Create a new Car" that popups, the popup is a form that is hidded and you call a jQuery UI command $('formName').dialog() to popup it, this form has the attributes of the possible new car, so probably a new view with a strongly typed Car. After fill in the form the database should be populated with the new car, and the list of cars should be refreshed using Ajax.
The main problem is that I can't use HTML Helpers to IList <Car> and for Car at the same time.

Briefly: What is the strongly type for that view ? Is it possible to define two views and the other one call using pop-up? Changing it to Razor would solve my problem?

Best regards,

Tito Morais

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

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

发布评论

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

评论(2

风筝在阴天搁浅。 2024-12-18 02:12:05

不要将列出汽车和创建新车的视图混在一起。

例如,您可以使用 jQuery 对话框或类似组件创建一个动态加载“_CreateCar”部分视图的弹出窗口。然后,当部分视图完成时,使用另一个 Ajax 调用重新加载列表视图。

Don't mix the views for listing the cars and creating a new car together.

For instance, you can make a popup that dynamically loads a "_CreateCar" partial view, using jQuery dialog or similar component. Then when the partial view is completed, reload the list view using another Ajax call.

你的心境我的脸 2024-12-18 02:12:05

也许不是一个优雅的解决方案是创建一个复杂的视图模型,例如:

class ListAndCreate
{
 public IList<Car> AllCars {get;set;}
 public Car NewCar {get;set;}
}

IMO,这是正确的,因为一个视图负责列出所有汽车并创建一辆新汽车。现在,我假设您的 NewCar 具有来自控制器或其他东西的值,您需要将模型传递到视图。

@Jonas 提到的另一种方法也是正确的并且更加统一。您可以创建一个 Car 类型的分部视图 _CreateCar,使用 Jquery/Ajax 渲染它以将其加载到对话框/弹出窗口中,并将表单 POST 到 Create控制器中的 (Car c) 方法。

Maybe not so much an elegant solution is to create a complex view model like:

class ListAndCreate
{
 public IList<Car> AllCars {get;set;}
 public Car NewCar {get;set;}
}

IMO this is correct since that one view is responsible for listing all cars and creating a new one. Now, I'm assuming that your NewCar has values coming from your controller or something, where you need to pass a model to your view.

The other approach, that @Jonas mentions is also correct and more unitized. You could create a partial view _CreateCar with type Car, render it with Jquery/Ajax to load it into a dialog/popup and have the form POST to a Create(Car c) method in your controller.

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