Form swapping with ASP.Net MVC 4, jQuery and Ajax

In this screen cast I will demonstrate how swap forms within in a section of your page using jQuery and AJAX.

This technique allows you to make your web sites faster and provide an easier (and better user experience).

Get the source code by clicking here.

Financial Functions in .Net (C#)

I recently worked on a project where I had to perform financial calculations. The main project requirements where provided on an Excel and because of the sensitivity of the calculations(mortgage payments), I had to keep within 1cent accuracy.

After reviewing the needed calculations, my main issue was the NPV (Net Present Value); although I am familiar with the formula and applications of NPV, I was not sure of the exact implementation in Excel.

So, I jumped to Google to see if there was any implementations and found the Excel Financial Functions for .Net: “… a .NET library that provides the full set of financial functions from Excel.”.

Great! BUT. The library is actually implemented in F# and only the source code is provided, no compiled version…. No problem, since all .Net languages compile into IL (Intermediate Language), all I needed to do was to compile the F# project and then reference it on my C# one.

After I add ed the Financial.dll reference to my project (compiled version included in the provided source code), I am ready to use it on my code, however, note that the following reference is required:

using

System.Numeric;

 

With the reference in place, I can now use the NPV function as follow:

Financials

Comparing the signature of the NPV function on Financial.dll to excel, we can see they are virtually the same:

Financials-Excel

And even though I have shown mainly the NPV usage, this library contains implementation pretty much all financial functions in Excel (Complete List).

There you have it; if you ever have a project where you need to use Excel functions, you can refer t the Excel Financial Functions for .Net library; you can use the compiled library provided on this example, but I recommend reviewing the library page regularly to check for updates.

Hope this helps!

ASP MVC3 – Editing records with jQueryUI Dialogs and AjaxForms – Razor Version

This post is in response to the several requests I’ve gotten to provide a Razor version of a sample solution I provided a few months ago on Editing records with jQueryUI Dialogs and AjaxForms, which was originally posted using aspx views. If you haven’t read it or seen the video, please take a look at it first; as most of the concepts will remain the same. You can also see what we are aiming to do the Demo Page.

So this solution is practically unchanged compared to the original, however I did I introduced 2 improvements (which could also apply to the aspx version).

  1. I realized after I did my original post that I was able to get data on the handler function from the ajax form; so I am no longer looking into the response div for my data (which was kind of a hack). Instead I am now using it properly by receiving the data directly.
  2. I use a JsonStandardResponse, which I have been using in my projects succesfully and make things a bit easier. (See my previous post: Json Standard Responses for your Ajax Calls). So the controller action was changed to return JsonResult instead of a regular ActionResult with Content.
Here are the details of the change in the controller:
[HttpPost]
public JsonResult Edit(CarModel model) {
if (ModelState.IsValid)
{
CarModel car = CarRepository.GetCars().Where(c => c.Id == model.Id).FirstOrDefault();
car.Name = model.Name;
car.Description = model.Description;
return Json(JsonResponseFactory.SuccessResponse(car),JsonRequestBehavior.DenyGet);
}
else {
return Json(JsonResponseFactory.ErrorResponse("Please review your form"), 
            JsonRequestBehavior.DenyGet);
}
}

Continue reading

Three ways to get started with KendoUI Grids on ASP.NET MVC

– Disclaimer: I do not work for KendoUI (Telerik) and I am not getting anything in return for this entry… I just like the library ;)

Over the past months I have been evaluating the KendoUI library and using it on my pet projects. I really like it, is evolving very fast and has good community around it.

KendoUI Grids are very flexible and can be used in many different ways. In this post I will show how you can get started with KendoUI grids on your ASP.NET MVC Projects., I will show you three different ways I have used them, which include Creating the Grid starting from a basic ASP.NET MVC List Template, Creating the grid over an empty div with a remote data source, and finally, how to create a grid using KendoUI templates.

These walk-troughs will cover most of the basics but are only intended to get you started; I encourage you to go to KendoUI.com and view all other options/configurations/methods available.

Want to see it action? See the Demo Page  or Download the Code

Method 1: Grid over Existing HTML

In this example, we start from the MVC List Template and convert it to a fully functional grid with pagination and sorting.

Continue reading

ASP.Net MVC: Using Json Standard Responses for your Ajax Calls

For the past couple of years, after we started our move towards ASP.Net MVC, we have been using more and more ajax to enrich our user interface and we love it.

At the begining we use to send our responses as simple strings (true/false) or very customized Json responses. However, for the past year or so we’ve been using Standard Json Responses and it has been working great. I’ve passed this idea to a couple of friends and everyone seems to like it so here it is.

Objective & Advantages

The objective will be to have standard Json Responses to our AJAX calls that we can easily re-use accross our application, independent of what action or what objects we are working with… And by having and standard responses, we can have a standard way to handle them.

Want to see it action? See the Demo Page  or Download the Code
Continue reading

ASP MVC3 – Editing records with jQueryUI Dialogs and AjaxForms

In this screen cast I will show you a demo of how to use  jQueryUI dialogs and MVC AjaxForms to create a rich and simple experience for users when editing records.

The technique is simple; you dynamically load a partial view into the DIV dialog  . There are a few tricks to wire up the validation, and to identify success over failure. .

Get the source code by clicking here, take a look and let me know what you think.

Update: 

After many requests, I’ve created a Razor version, all interested can read the post here. 

Quick Fix for AddThis.com’s Facebook Like Button in IIS7.0

In this post I will be addressing how to fix an error with AddThis.com’s Facebook Like button, that results int he following error:

Parser Error Message: The string ‘fb:like:layout’ contains too many device filters. There can be only one.

Continue reading

In case you missed it: App_Offline.htm

I recently found out about a featured introduced in ASP.Net 2.0 that makes it pretty easy to take your application offline, which is pretty useful for when you are doing upgrades, releases, etc. I’m not sure how I missed this as it has been out there for at least a couple of years, but still wanted to do a post about it in case other people missed it as well.

Continue reading

Improving Silicon Halton’s Business Directory

About Silicon Halton

In a nut shell, Silicon Halton is a group dedicated to connecting and creating strong and local relationships for hi tech entrepreneurs and leaders in the Halton region.

I have been attending Silicon Halton’s meetings (and un-meetings) for a few months now (http://www.siliconhalton.com/); I am both impressed and encouraged by the groups potential; obviously there is networking and the possibility of making new business connections, but the group also aims to play a role in the Halton business community as a whole… and that is what’s kept me going back!

Continue reading

ASP MVC – Delete confirmation with Ajax & jQuery UI Dialog

In this post I will show you how I implemented a delete confirmation implementation for MVC using the jQuery UI Dialog control. I have done this by adding virtually no customization to the templates generated ASP.Net MVC, and aiming the functionality to be as reusable as possible.

Our Objective

When a user clicks the “Delete” button on a list (or elsewhere), we are going to show a confirmation dialog. If the user confirms, the record will be deleted. If he/she cancels, no action will be taken. In essence, this is what we are trying to do:

Continue reading

Follow

Get every new post delivered to your Inbox.

Join 215 other followers