Reputation: 43
I'm trying to combine a MVC project to EmberJS. I searched for existed questions but I only came this far by those: I created something with ember new emberProject
and wrote simple templates, routes, models, mirage etc. Then I created an MVC web API and in the controllers, I created AppController and write this:
public class AppController : Controller
{
// GET: App
public ActionResult Index()
{
return File(Server.MapPath("~/emberProject/dist/") + "index.html", "text/html");
}
}
and for the index I write the path:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/emberProject/dist/assets/vendor.css">
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
</div>
</body>
</html>
What should I do after this? Shouldn't I see my .hbs
and .js
files on the MVC project? Because I can't. Also, right now I'm using hard-coded dummy data. I need to take data from MVC in order to use as a "model" on my ember project. What should I do?
Thanks.
Upvotes: 0
Views: 769
Reputation: 18240
Its strongly recommended by the ember community to keep your frontend application and your API backend separated. This is also a requirement if you want to use ember-cli
So you would only use your asp.NET MVC application to serve your data and your static assets. For development you would start your ember-cli
project with ember serve --proxy=http://your-asp.net_mvcproject/
, so that all API requests are proxied to your asp.NET Backend.
Then you should create a API in your asp.NET MVS project to access your data, I recommend to use the JSONAPI
, which is the ember default implementation.
Then you can build your client application only with ember-cli
, without asp.NET MVC, only getting your data from your backend.
The integration is then only required for deployment, where you need to server your static files build with ember build --prod
and as fallback you always serve the ember index.html
file, so ember can boot up and the ember router can decide what to do then.
The other way is to integration ember in your asp.net MVC project. This is absolutly possible, but you should do this only if you understand both, the ember-cli
build pipeline and the asp.NET project structure very well. If you do this you would have to do a lot of things yourself that are handled by ember-cli
.
For example you would need to transpire ES6 to ES5 yourself, and you could not use any ember-cli
addons out of the box. Also you would probably need to compile your templates, and implement a custom resolver.
Upvotes: 4