Hi all
i want to get selected row and pass the ProductID to controller action, these is my code
@model TelerikMvcApp2.Models.Products@{
ViewBag.Title = "1";
var ProductID = 0;
int x = 0;
}
<h2>Index</h2><div>
@ProductID
</div><div>
<h4>Basic Button</h4>
<p>
@(Html.Kendo().Button()
.Name("primaryTextButton")
.HtmlAttributes( new {type = "button", @class = "k-primary" } )
.Content("Clear"))
</p>
</div>
<div id="clientsDb">
@(Html.Kendo().Grid<TelerikMvcApp2.Models.Products>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.ProductID).Width(140);
columns.Bound(c => c.ProductName).Width(190);
columns.Bound(c => c.UnitPrice);
columns.Bound(c => c.UnitsInStock).Width(110);
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Sortable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Row))
.Events(events => events.Change("onChange"))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Customers_Read", "Home"))
)
)
</div> <div>
<img name="Pic1" alt="test" src='@Url.Action("Events", "Home", new { id = @ProductID })'/>
</div>
<script type="text/javascript"> function onChange()
{
var selectedrow = $("#grid").find("tbody tr.k-state-selected");
var goods = $('#grid').data("kendoGrid").dataItem(selectedrow);
var goodsjson = goods.toJSON();
var goodsID = goodsjson.ProductID;
document.Pic1.src = '@(Url.Action("Events", "Home", new { id= goodsID}))';
}</script>
it can build successfully but when run it, it will show The name 'goodsID' does not exist in the current context
i want to get selected row and pass the ProductID to controller action, these is my code
@model TelerikMvcApp2.Models.Products@{
ViewBag.Title = "1";
var ProductID = 0;
int x = 0;
}
<h2>Index</h2><div>
@ProductID
</div><div>
<h4>Basic Button</h4>
<p>
@(Html.Kendo().Button()
.Name("primaryTextButton")
.HtmlAttributes( new {type = "button", @class = "k-primary" } )
.Content("Clear"))
</p>
</div>
<div id="clientsDb">
@(Html.Kendo().Grid<TelerikMvcApp2.Models.Products>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.ProductID).Width(140);
columns.Bound(c => c.ProductName).Width(190);
columns.Bound(c => c.UnitPrice);
columns.Bound(c => c.UnitsInStock).Width(110);
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Sortable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Row))
.Events(events => events.Change("onChange"))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Customers_Read", "Home"))
)
)
</div> <div>
<img name="Pic1" alt="test" src='@Url.Action("Events", "Home", new { id = @ProductID })'/>
</div>
<script type="text/javascript"> function onChange()
{
var selectedrow = $("#grid").find("tbody tr.k-state-selected");
var goods = $('#grid').data("kendoGrid").dataItem(selectedrow);
var goodsjson = goods.toJSON();
var goodsID = goodsjson.ProductID;
document.Pic1.src = '@(Url.Action("Events", "Home", new { id= goodsID}))';
}</script>
it can build successfully but when run it, it will show The name 'goodsID' does not exist in the current context