I'm trying to figure out mvc, so I have problem... I have this model:
public class Company
{
public string ID { get; set; }
public string Symbol { get; set; }
public string Description { get; set; }
}
and controller:
public ActionResult EditCompany()
{
ViewBag.Message = "Edit Company Page";
return View();
}
public ActionResult PartialEditCompany()
{
DataSet dataSet = client.SelectCompanies();
ObservableCollection<Company> inventoryList = new ObservableCollection<Company>();
foreach (DataRow dataRow in dataSet.Tables[0].Rows)
{
inventoryList.Add(new Company
{
ID = (String)dataRow["ID"],
Symbol = (String)dataRow["Symbol"],
Description = (String)dataRow["Description"]
});
}
return PartialView(inventoryList);
}
and view EditCompany:
@model Test.Models.Company
@{
ViewBag.Title = "EditCompany";
}
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Content/mycss.css" rel="stylesheet" />
<script>
$('#loadData').click(function () {
$('#partial').load('/HomeController/PartialEditCompany/');
});
</script>
<div id="stylized2" class="myform">
@using (Html.BeginForm("SaveCompany", "Home", FormMethod.Post, new { @class = "insertcompanyform" }))
{
@Html.ValidationSummary(true)
<table>
<tr>
<td class="first">@Html.Label("ID:")
</td>
<td class="second">@Html.TextBoxFor(m => m.ID)</td>
</tr>
<tr>
<td class="first">
@Html.Label("Symbol:")
</td>
<td class="second">@Html.TextBoxFor(m => m.Symbol)</td>
</tr>
<tr>
<td class="first">
@Html.Label("Description:")
</td>
<td class="second">@Html.TextBoxFor(m => m.Description)</td>
</tr>
<tr>
<td class="third"><input type="button" value="Traži" id="loadData" /></td>
</tr>
<tr>
<td>
<div id="partial"></div>
</td>
</tr>
and finnaly partialview PartialEditCompany:
@using System.Web.Helpers
@{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);
}
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Content/mycss.css" rel="stylesheet" />
@Html.WebGrid()
What I want to do is on button click (with id=loadData) to call partial view that will put grid into div tag (with id=parital). Please help! What am I doing wrong?