I have a Telerik MVC grid in my application and a context menu set on the grid as well. When user clicks on the context menu, the action of the controller expects current row's id and some other data as a parameter. How can I pass this information to the action/controller from the context menu's item click?
The action is supposed to return a PDF file, so I can't use .Ajax in this case.
Here is code for the grid, context menu and the Action method.
public
ActionResult ExportToPdf(
int
caseId,
string
caseNo)
{
var rd =
new
ReportDocument();
var server = @
"SERVERNAME\SQLEXPRESS"
;
var database = @
"XYZ"
;
rd.Load(Path.Combine(Server.MapPath(
"~/Reports"
),
"reportName.rpt"
));
rd.DataSourceConnections[0].SetConnection(server, database,
"abc"
,
"dbPassword"
);
Response.Buffer =
false
;
Response.ClearContent();
Response.ClearHeaders();
var stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return
File(stream,
"application/pdf"
, String.Concat(caseNo,DateTime.Now.ToShortDateString(),
".pdf"
));
}
@(Html.Kendo().Grid<
IMCC.CTS.Models.CaseMasterViewModel
>()
.Name("caseSearchGrid")
.Columns(columns =>
{
columns.Bound(c => c.case_number).Width(105);
columns.Bound(c => c.note_number).Width(105);
columns.Bound(c => c.title).Width(300);
columns.Bound(c => c.instituion_date).Width(115);
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.id))
.Read(read => read.Action("Search_Read", "Search").Data("GetSearchData"))
)
)
01.
@(Html.Kendo().ContextMenu()
02.
.Name(
"menu"
)
03.
.Target(
"#caseSearchGrid"
)
04.
.Filter(
"tr[role = 'row']"
)
05.
.Events(ev => { ev.Select(
"onSelect"
); })
06.
.Orientation(ContextMenuOrientation.Vertical)
07.
.Animation(animation =>
08.
{
09.
animation.Open(open =>
10.
{
11.
open.SlideIn(SlideDirection.Down);
12.
open.Duration(250);
13.
});
14.
})
15.
.Items(items =>
16.
{
17.
items.Add().Text(
"Export"
).
Action(
"ExportToPdf"
,
"Search"
,
new
{ caseId = 1, caseNo =
" abc"
});
//here grid's selected Model's id or row's id and selected row's case_number should be passed.
19.
items.Add().Text(
"Export to PDF 2"
).Encoded(
false
).HtmlAttributes(
new
{ id =
"ExportToPdf2"
});
// i can send this data through Ajax call, but that does not allow returning PDF from the action method.
20.
})
21.
)