我有下拉列表,我已从数据库中填写.现在我需要在Controller中获取所选值进行一些操作.但没有得到这个想法.我试过的代码.
public class MobileViewModel
{
public List<tbInsertMobile> MobileList;
public SelectList Vendor { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
public ActionResult ShowAllMobileDetails()
{
MobileViewModel MV = new MobileViewModel();
MV.MobileList = db.Usp_InsertUpdateDelete(null, "", "", null, "", 4, MergeOption.AppendOnly).ToList();
MV.Vendor = new SelectList(db.Usp_VendorList(), "VendorId", "VendorName");
return View(MV);
}
[HttpPost]
public ActionResult ShowAllMobileDetails(MobileViewModel MV)
{
string strDDLValue = ""; // Here i need the dropdownlist value
return View(MV);
}
Run Code Online (Sandbox Code Playgroud)
<table>
<tr>
<td>Mobile Manufacured</td>
<td>@Html.DropDownList("ddlVendor", Model.Vendor, "Select Manufacurer") </td>
</tr>
<tr>
<td>
</td>
<td> …Run Code Online (Sandbox Code Playgroud) 我开发了一个C#Windows应用程序,我需要在客户端计算机上创建一个数据库,我已经在客户端计算机上创建了一个脚本文件并安装了SQL Server 2008 R2.
但是当我从我的代码执行脚本时,它总是显示错误:
无法连接数据库.
我添加了引用的SMO程序集
C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\Microsoft.SqlServer.Smo.dll
Run Code Online (Sandbox Code Playgroud)
我的代码是:
string sqlConString = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=mydatabase;Data Source=(local)";
FileInfo file = new FileInfo(dbPath);
string script = file.OpenText().ReadToEnd();
SqlConnection con = new SqlConnection(sqlConString);
Server server = new Server(new ServerConnection(con));
server.ConnectionContext.ExecuteNonQuery(script);
file.OpenText().Close();
Run Code Online (Sandbox Code Playgroud)