小编Rag*_*bar的帖子

如何在MVC中的Controller中获取DropDownList SelectedValue

我有下拉列表,我已从数据库中填写.现在我需要在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# asp.net asp.net-mvc asp.net-mvc-4

44
推荐指数
3
解决办法
33万
查看次数

无法使用smo从c#执行脚本

我开发了一个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)

c# sql-server asp.net winforms

2
推荐指数
1
解决办法
1190
查看次数

标签 统计

asp.net ×2

c# ×2

asp.net-mvc ×1

asp.net-mvc-4 ×1

sql-server ×1

winforms ×1