2012-07-06 52 views
0

如何更新表中的多行?更新多個記錄數據庫MVC C#

控制器:

[HttpGet] 
public ViewResult Index() 
{ 
    return View(ConfI.Conf.ToList()); 
} 

[HttpPost] 
public ActionResult Index(Configs conf) 
{ 
    ConfI.SaveConfig(conf); 
    return View();   
} 

的Index.aspx:

<% using (Html.BeginForm()) 
    {%> 
<% foreach (var x in Model) 
    {%> 
<%: Html.Hidden(x.option_name) %> 
<%: Html.Hidden(x.ID_option.ToString()) %> 
<%: Html.Encode(x.option_title) %> 
<%: Html.TextBox("option_value", x.option_value) %><br /> 
<% } %> 
<input type="submit" value="save" /> 
<% } %> 

Configs.cs - 我沒有寫,還有變量表

Sqlconfig.cs :

public class SqlConfig : IConfiguration 
{ 
    private Table<Configs> ConfigTable; 
    public SqlConfig(string connectionString) 
    { 
     ConfigTable = (new DataContext(connectionString)).GetTable<Configs>(); 
    } 

    public void SaveConfig(Configs config) 
    { 
     ConfigTable.Attach(config); 
     ConfigTable.Context.Refresh(RefreshMode.KeepCurrentValues, config); 
     ConfigTable.Context.SubmitChanges(); 
    } 
} 

謝謝!

回答