Aftersubmit event in Trirand jqgrid Commercial - asp.net-mvc-4

Can someone tell me how to use AfterSubmit Event in Commercial jqgrid for ASP.Net MVC? Im not able to find enough documentation for commercial JQGrid.

I solved it by defining the ClientSideEvents - on the server side.
chargesJQGrid.ClientSideEvents.AfterAddDialogRowInserted = "AfterInsert";
chargesJQGrid.ClientSideEvents.AfterDeleteDialogRowDeleted = "AfterDelete";
Then implemented the javascript method
function AfterInsert(response,postdata)
{
}
function AfterDelete(response,postdata)
{
}

Related

Rendering .rdlc reports with ASP .NET Core

Is it possible to render .rdlc reports with ASP.NET Core? Currently this only seems to be possible if I target the .NET Framework as opposed to .NET Core.
I don't need a report viewer I just need to render the results of an .rdlc report as a byte array.
If you want to create pdf/excel/word using rdlc report I recommend you can use AspNetCore.Reporting library. This is open source and comes as a nuget package. you can integrate this in your .NET Core API or .NET Core Azure function. You can generate a byte array convert it to base 64 string and retrieve that to your client side. More on the link in the comment.
You very well can render rdlc into a byte array. Please see a related question I asked a while back. RDLC Local report viewer for ASP.NET Core and Angular(>2.0).
Eventually a creative discussion on that thread resulted in an angular package(https://www.npmjs.com/package/ng2-pdfjs-viewer - Disclosure; I am the author) with consumable rdlc byte array functionality on client side. Of course, instead of this package, you may choose another javascript library to display the byte array.
A simple usage on angular would be like this. Please note, most of the code can be reused even if you are using plain js or another framework.
The below code demonstrates
1. Spitting byte array using RDLC report viewer control on aspnet core action method(on server side) and sending it over wire using http. (Code is in C#)
2. Processing response's byte array into a blob object (Js)
3. Feeding blob object into ng2-pdfjs-viewer.
4. ng2-pdfjs-viewer internally uses Mozilla's PDFJS to accomplish the feat of displaying the PDF on browser.
(FYI.. I took code from samples provided on ng2-pdfjs-viewer package. Replace step 3 and 4 if you are using another library or plain javascript)
<!-- your.component.html -->
<button (click)="showPdf();">Show</button>
<div style="width: 800px; height: 400px">
<ng2-pdfjs-viewer #pdfViewer></ng2-pdfjs-viewer>
</div>
export class MyComponent implements OnInit {
#ViewChild('pdfViewer') pdfViewer
...
private downloadFile(url: string): any {
return this.http.get(url, { responseType: ResponseContentType.Blob }).map(
(res) => {
return new Blob([res.blob()], { type: "application/pdf" });
});
}
public showPdf() {
let url = "http://localhost/api/GetMyPdf";
this.downloadFile(url).subscribe(
(res) => {
this.pdfViewer.pdfSrc = res; // <---- pdfSrc can be Blob or Uint8Array
this.pdfViewer.refresh(); // Ask pdf viewer to load/reresh pdf
}
);
}
[HttpGet]
[Route("MyReport")]
public IActionResult GetReport()
{
var reportViewer = new ReportViewer {ProcessingMode = ProcessingMode.Local};
reportViewer.LocalReport.ReportPath = "Reports/MyReport.rdlc";
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource1", reportObjectList1));
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource2", reportObjectList1));
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
var bytes = reportViewer.LocalReport.Render("application/pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);
return File(bytes, "application/pdf")
}
In case anyone is still looking for a similar solution, I would recommend using "ReportViewerCore.NETCore".
Here is the nuGet reference - https://www.nuget.org/packages/ReportViewerCore.NETCore/
Here is the github link to the repo - https://github.com/lkosson/reportviewercore/
Basic usage
Stream reportDefinition; // your RDLC from file or resource
IEnumerable dataSource; // your datasource for the report
LocalReport report = new LocalReport();
report.LoadReportDefinition(reportDefinition);
report.DataSources.Add(new ReportDataSource("source", dataSource));
report.SetParameters(new[] { new ReportParameter("Parameter1", "Parameter value") });
byte[] pdf = report.Render("PDF");
You can not render .rdlc reports in .NET Core, using .rdlc as a byte array.
Rendering RDLC reports relies on WinForms and WebForms and is currently only supported on .NET Framework. Hopefully Microsoft will make a (slimmed down) version available (just rendering the reports for starters) on .NET Core or .NET 5, but no word as of yet.
As an alternative, you could go for a solution where you run report rendering as a separate ASP.NET 2 app targeting .NET Framework, while the rest of your app could target .NET Core 3 or later. That way, you can call the reporting endpoints with the appropriate data, and it returns a rendered report.
This is what I've done, creating a sort of microservices architecture where multiple .Net Core 3.1 apps can post both the XML RDLC report definition and data to an endpoint running on net48, which uses the LocalReport class to render the report to the desired format, returning it as a byte array.
Angular app | ----> | APIs (.Net Core 3.1) | ----> | API (.Net Framework 4.8)

How to Call JavaScript Function in Controller mvc

I have one javascript function which is writted in view and i want call that function in Controller.the javascript takes input parameter and return one result. i have to store that value in string or variable.can anyone please help me in this.thanks in advance.here i mentioned my sample JavaScript here,
function GetLong(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
long = results[0].geometry.location.lng();
} else {
alert("Request failed.")
}
});
return long;
};
The purpose of the MVC framework is to seperate Model, View and Controller. You can't invoke a javascript code from the MVC-Controller since the view is rendered and displayed in the client browser. You can invoke the javascript code in the view and send a POST or GET request to your Server for if you need a dynamic comunication between your view and controller.
If you want to use that javascript code in C# for example you might want to have a look at this https://github.com/jonsagara/geocodingapi
Or this Answer might be helpful aswell Google Maps v3 geocoding server-side

I am getting a $save() not a function in Angular

I am trying to build a relatively simple web application following tutorials from the book ProAngular. The book examples work fine, but when I try and build my own app, I am getting stuck on a strange error. Here is part of my code:
$scope.dispositionsResource = $resource(dispositionUrl + ":id", { id: "#id" },
{ create: {method: "POST"}, save: {method: "PUT"}, delete: {method: "DELETE"}
});
. . .
$scope.updateDisposition = function (disposition) {
alert("DISPOSITION: "+disposition.name);
disposition.$save();
}
The Create and Delete functions work fine. The updateDisposition method is being called form an HTML form and the correct disposition value is being passed (based on the Alert). But the error I am getting is:
"Error: disposition.$save is not a function"
None of my example code separately defines a save function, the function should be part of the restful service ($resource). Shouldn't it?
Any pointers in the right direction would be greatly appreciated.
Ted
I did end up getting this working. Not totally sure why, but I renamed the Save function to 'Update' and associated it with the PUT functionality.
$scope.dispositionsResource = $resource(dispositionUrl+":id", { id: "#id" },
{ 'create': {method: "POST"}, 'update': {method: "PUT"}
});
$scope.updateDisposition = function (disposition) {
$scope.dispositionsResource.update(disposition);
$scope.editedDisposition = null;
}
calling update rather than save worked. Something seemed to be interfering with using the term 'save'. Like I said, not sure what . . . yet. One of those head-scratchers for me. Thanks to those who tried to assist!
I am learning angular myself, but the first problem I can see with your code is that it doesn't look like you are defining $resource correctly ( fair warning, Angular has a ton of caveats and you may simply be delving into one I am not aware of).
I believe a more straight forward way of doing what you are trying to do is first creating an angular factory for the $resource, like so:
angular.module('yourModuleName')
.factory('disposition', function($resource) {
return $resource('/whatever/url/youwant/:id', {
id: '#id'
})
});
And then from there, declare the factory as a dependency for your controller:
angular.module('yourModuleName')
.controller('yourControllerName', function($scope, disposition) {
$scope.submitForm = function($scope)
disposition.save($scope.nameOfYourModel);
});
One thing to keep in mind is that $resource has all of the methods that you declared by default. From the docs at https://docs.angularjs.org/api/ngResource/service/$resource these are what are available out of the box:
{ 'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'} };
Personally, I prefer to use the $http service myself. Yes, it is quite a bit more verbose than using $resource but I feel that it is much easier to understand $http when starting with angular than the $resource service. To save yourself from a world of headaches in the future, I highly recommend becoming familiar with the concept of promises in Angular as many of its services make use of them.
Good luck.

Restlet creation doesn't return ID

I'm currently PoCing a solution for OData interaction from Java. We have an WCF odata repository available. I began preliminary coding using the restlet API because it has code generation available but since using it I've encountered the situation where a newly created object doesn't have it's ID set upon creation and the addEntity method in the generated service class doesn't appear to return the ID?
Which is a more comprehensive solution, that from Restlet or OData4j?
Thanks,
Mark.
you can manually return the id where you are implementing the producer register method
for example:
producer.register(yourModelClass.class, "yourModelClass", new Func1<Object,Iterable<yourModelClass>>() {
public Iterable<yourModelClass> apply(Object queryInfo) {
return null;
}
}
}, "yourID");

Same parameters,different methods

I'm making an API in asp mvc 4.
I have 2 methods, GetAllBooks() and GetPopularBooks().
To get all books, I call localhost:xxxxx/api/books/, and I get the correct result.
How can I query the popular books? Both methods are parameterless and our info here is not really helpful.
All help is appreciated!
Although this could be achieved using "Routing by Action Name" http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api. I strongly suggest that GetPopularBooks() be treated as GetAllBooks but with a filter of popularity.
e.g.
public IEnumerable<Books> GetAllBooks([FromUri]bool? IsPopular = null)
{
if(IsPopular.HasValue)
{ //do something
//return filtered
}
//return all
}
Urls:
http://localhost/api/books
http://localhost/api/books?isPopular=true