hi
I used below codes to show data in table:
Controller:
public ActionResult List()
{
DataSet ds = new DataSet();
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "SELECT * FROM Resellers";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(ds);
}
}
}
return View(ds);
}
View:
@using System.Data
@model DataSet
<div id="divSearch">
<table class="table-full table-total">
@foreach (DataRow row in Model.Tables[0].Rows)
{
<tr>
<td>
@row["Name"]
</td>
<td>
@row["Address"]
</td>
</tr>
}
</table>
</div>
it will shows data from database in Table
now I want bind 2 dropdownlist in this view so I worte below code:
private static List<SelectListItem> PopulateOstan()
{
SqlConnection constr = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Constring"].ConnectionString);
List<SelectListItem> items = new List<SelectListItem>();
using (SqlCommand cmd = new SqlCommand("SelectOstan", constr))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Connection = constr;
constr.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
items.Add(new SelectListItem
{
Text = sdr["Name"].ToString(),
Value = sdr["id"].ToString()
});
}
constr.Close();
}
return items;
}
}
public ActionResult List()
{
var model = new SearchViewModel();
model.Ostans = PopulateOstan();
model.Citeies = PopulateCiteies1();
return View(model);
}
SearchViewModel:
public class SearchViewModel
{
public IEnumerable<Reseller> Reseller1 { get; set; }
public DataTable Reseller { get; set; }
public List<SelectListItem> Ostans { get; set; }
public List<SelectListItem> Citeies { get; set; }
}
now I want use both Dateset and viewmodel in one view so I should wrote below codes:
@model MvcInternetShop.ViewModels.Test.SearchViewModel
@using System.Data
@model DataSet
but it makes below error
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Only one 'model' statement is allowed in a file. Source Error:
Line 3: @model MvcInternetShop.ViewModels.Test.SearchViewModel
Line 4: @using System.Data
Line 5: @model DataSet
Line 6:
Line 7: @{
|