【发布时间】:2016-04-17 06:33:27
【问题描述】:
我创建了一个带有公司名称 DropDownList 的投标 Web 应用程序。我从特定目录中获取这些名称,放入数组并复制到列表中,然后添加字符串“-Add new-”,以便在用户选择此选项时创建操作。
第一个问题:当用户选择“-Add new-”时,如何创建一个打开一个带有文本框的小窗口的操作,并且在输入名称并单击“Add”后,它会在其中创建一个新文件夹我的“\我的网络目录\”?
第二个问题:正如我之前所说,公司名称的DropDownList来自“\我的网络目录\”,我如何传递用户选择的值(公司名称)并在另一个DropDownList中显示子-选择的文件夹(公司)的目录?
//The controller
public class TenderController : Controller
{
//
// GET: /Tender/
public ActionResult AddNewTender()
{
//Get companies directory and put it into a string array
string[] compNameArray = Directory.GetDirectories(@"//My network directory\");
int i = 0;
foreach (string txtName in compNameArray)
{
//Copy to another string every directory name only with the las name file (the company name)
string txtDirName = txtName.Substring(txtName.LastIndexOf(@"\") + 1);
//Update the companies name array with the companies name only
compNameArray[i] = txtDirName;
i++;
}
//Copy the companies name array to a list
List<string> compList = new List<string>(compNameArray);
//Remove from the list the names above
compList.Remove("New folder");
//Add the "add new" option to the list
compList.Add("-Add new-");
ViewBag.ListOfCompanies = compList;
return View();
}
观点:
<td dir="rtl">
@Html.DropDownList("companyName", new SelectList(ViewBag.ListOfCompanies, Model))
</td>
【问题讨论】:
-
这种情况下你应该使用javascript
-
我不太擅长 javascript... 你能解释一下具体是怎么做的吗?
-
你应该查看一些教程。喜欢this
标签: c# asp.net asp.net-mvc asp.net-mvc-4 html.dropdownlistfor