简体   繁体   English

Asp.net MVC 3视图设计

[英]Asp.net MVC 3 view design

I have a table that has attributes not common to all rows that will be inserted, which mean my schematic will allow some columns to be empty and this will depend on the type selected. 我有一个表,该表具有并非将要插入的所有行共有的属性,这意味着我的原理图将允许某些列为空,这取决于所选的类型。

The tables 桌子

Item table

ItemId
Name
Location
Typeid

Type table

Typeid
Desc

Upon a certain type selected (from a dropdown) in the form, some attributes in the item would be shown to the user and they would be have to be entered. 在表单中(从下拉列表中)选择了某种类型后,该项目中的某些属性将显示给用户,并且必须输入它们。 How do I approach this. 我该如何处理。

You'll likely have a controller action (probably a controller) per table so you get separate urls for SEO. 每个表中可能会有一个控制器动作(可能是一个控制器),因此您将获得SEO的单独URL。 You'll also want a view per table as well as these values aren't really shared. 您还需要每个表的视图,以及这些值并未真正共享。 You could create an ivory castle that would render a table given a generic List or DataTable, but if you're leaning that route, just use a control for it. 您可以创建一个象牙城堡,该城堡将在给定通用List或DataTable的情况下呈现一个表,但是如果您遵循该路线,则只需对其使用控件即可。

You can also do it with Javascript and AJAX. 您也可以使用Javascript和AJAX来实现。 You can have a div which is hidden called 'item-form'. 您可以将其隐藏的div称为“ item-form”。 And on selecting one of the dropdown options, a javascript function can fill the item-form with the html for the selected item type (with the necessary attributes) and make the div visible. 并且在选择下拉菜单选项之一时,javascript函数可以使用所选项目类型(具有必要属性)的html填充项目表单,并使div可见。

Something like - 就像是 -

$("#dropdown").change(function(){
    if($(this).val()==1)
        $("#item-form").html(); //form with the attributes for type 1
    else if ($(this).val()==2)
        $("#item-form").hmtl(); //form with the attributes for type 2

});

You could fill the div's using calls to controller actions that are specific to the type selected which would return partial views. 您可以使用对特定于所选类型的控制器操作的调用来填充div,这将返回部分视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM