Asp.Net MVC html.DropDownList 根据所选值的操作
Asp.Net MVC html.DropDownList Action according to selected value
我创建了一个带有公司名称 DropDownList 的 Tenders 网络应用程序。我从特定目录中获取这些名称,将其放入数组中并复制到列表中,然后添加字符串“-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>
第一个问题:
Run javascript after dropdownlist change.
在 Javascript 中,您应该检查下拉值。
那么你可以create a button from the Javascript.
点击"add"后,在控制器中创建一个动作来创建新文件夹。
第二题:
和第一个问题一样的技巧,使用onchange事件运行 Javascript。
在 Javascript 你可以 add values to dropdownlists.
我创建了一个带有公司名称 DropDownList 的 Tenders 网络应用程序。我从特定目录中获取这些名称,将其放入数组中并复制到列表中,然后添加字符串“-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>
第一个问题:
Run javascript after dropdownlist change.
在 Javascript 中,您应该检查下拉值。
那么你可以create a button from the Javascript.
点击"add"后,在控制器中创建一个动作来创建新文件夹。
第二题:
和第一个问题一样的技巧,使用onchange事件运行 Javascript。 在 Javascript 你可以 add values to dropdownlists.