【问题标题】:What's the best approach for dynamically loading an editor?动态加载编辑器的最佳方法是什么?
【发布时间】:2014-07-09 01:04:17
【问题描述】:

我对 ASP.NET MVC 还是很陌生(或者至少在更高级的场景中使用它时)——所以我正在寻找针对特定使用场景的反馈以及实现的最佳方法它。我已经尝试过多次搜索,但没有找到类似的东西。

我对实现它的方法非常灵活——只要提议的解决方案运行良好。

假设我有一个名为Vehicle 的实体,它与一个实体VehicleType 相关联,Vehicle 也与一个属性实体相关联,该实体基于VehicleType 称为VehicleProperties。例如 - 车辆类型可以是“Car”、“Boat”等,VehicleProperties 包含 Car VehicleType 的“BodyStyle”、“Color”等,以及“Boat”VehicleType 的“Length”、“Weight”等

On the create and edit forms for the VehicleConntroller I'm looking to do something along these lines: Have a drop down list of vehicle types and when the selection of that changes load the appropriate "VehicleProperties" form that is specific到这个 VehicleType。

这就是我的问题所在 - MVC 中最好的方法是什么?寻找 AJAX 类型的方法。如果有人有任何可以概述潜在解决方案的示例教程或文章 - 我将不胜感激!

我目前正在使用带有 jQ​​uery 的 ASP.NET MVC 5 - 但如果需要一个优雅的解决方案,我愿意添加其他 JS 库。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-ajax


    【解决方案1】:

    解决办法在这里,

    1.创建一个强类型视图,并为该视图创建一个返回 VehicleType 集合的操作方法,即 List

    2.因此,您可以通过使用 html 标记迭代模型来在视图中创建 DropDownlist。在您的情况下,模型是“List ”

    3.创建一个强类型的局部视图,VehicleProperties 类型。

    4.创建另一个带有参数的操作方法,该方法将返回具有适当车辆属性的局部视图;

    5.为 DropDownlist 编写一个 onchange java 脚本函数。通过 jQuery Ajax 调用 action 方法,以选择的下拉值作为参数。

    6. ajax 调用的响应将是 html 内容,您可以将其附加到 html div。

    完成..!!快乐编码..!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 2013-06-27
      • 2012-01-07
      • 1970-01-01
      相关资源
      最近更新 更多