Using Ember.js with .net mvc4 with razor

Hi guys, forgive me if I seem naive, I work closely with a .net developer and we have a project starting soon that i’d like to build using ember.js although is it practical to tie it in with .net mvc 4 with razor?

I really wish to learn and experiment with ember in this upcoming project having been impressed with the concepts although whats the general thought on combining a client and server side mvc structure together, is there much to benefit from this practice or is it a bit… counter-intuitive?

I’d really appropriated any feedback!

Many thanks,

Phil

I’ve been working on a project for the past few weeks which uses the ASP.NET Web API in MVC 4 as a backend to an ember application. My project doesn’t use razor at all. The only use case I could see for razor is making it serve up the initial application payload, but templates are going to be client side using handlebars.

The Web API / Ember approach is working really good for us so far. The two gotchas that we needed to work through were creating simple POCO classes that we would use as return values and arguments to the API Controllers. This allowed the .NET model binding and serialization to accept and create objects that ember-data was happy with.

Additionally I wrote a JSON.NET ContractResolver wich would create underscore attribute names for the JSON being returned from our api.

These two tweaks are only really necessary if you plan on using ember-data. I’ve also seen others use custom adapters / serializers for ember-data that work with the ASP.NET defaults. Personally I like the ember defaults better.

If you have any specific questions I would love to answer them if I can :smile:

-ray

1 Like

How exactly did you implement your two tweaks? From what I understand, it seems like you created custom models that returned JSON in the ember-data format? Would be great if you could share :smile:.

I’m not even sure what you mean by the second tweak. Could you expound on that?

I also prefer the REST spec. that Ember adheres to, and I’d rather start with that instead of using WebAPI’s format.

I’m currently working on a project. I want use emberjs and ASP.NET Web API. Is it possible to develop the ember application separately ? If so, how do you integrate the ember portion with the web api without using razor ?

If you want to develop them separately than I don’t see where razor would come into play. You would develop your frontend separate from your backend and the frontend would interface with your backend via XHR. Your Web API service would never be serving up your frontend assets.

Hi,

i m working in MVC 4 with ember js facing problem to call MVC partial view in HBS file

please help me