0

I'm currently making a web application with Asp.net MVC 5 (.Net Framework 4.6) and AngularJS 2.0 .

I take care the back-end and my friend takes care the front-end.

Now, he sends me 3 js files, 1 html file. Can anyone help me to import those file to MVC 5 please ?

Thank you,

1
  • Are you new to MVC? Commented Jun 10, 2016 at 6:36

2 Answers 2

2

I´m assuming you are new to MVC...

  1. Create a new MVC project.
  2. Copy your js files to Scripts. (Drag from explorer to visual studio)

The best way to go with js is to make a bundle:

  1. In app_start, open BundleConfig.cs
  2. Create a new Bundle like this:

    bundles.Add(new ScriptBundle("~/bundles/mybundle").Include( "~/Scripts/myjs1.js", "~/Scripts/myjs2.js", "~/Scripts/myjs3.js"));

  3. Now to render this bundle, open Views->Shared->_Layout.cshtml

  4. Go to the bottom, find @Scripts.Render("~/bundles/jquery")
  5. Add your bundle: @Scripts.Render("~/bundles/mybundle") Now, your js is available to all pages.
  6. We need to create a controller. Right click Controllers folder -> add -> Controller
  7. Select MVC5 Controller Empty.
  8. Give it the name you like for this page.

You will see this:

public class testeController : Controller
    {
        // GET: teste
        public ActionResult Index()
        {
            return View();
        }
    }

11. Right Click the Index in the code -> click in add View 12. VS will open the view. Paste your HTML here.

You are good to go!

Things to keep in mind 1 - ROUTES:

MVC default route (URL) is /controller/Action/id

In the example above, your url will be: /teste or /teste/index because it´s the controllers name.

If not provided MVC uses Home as controller name and Index as action name and id is optional.

So, if your page is the home page for the site put it in the Views -> Home -> index.cshtml

Things to keep in mind 2 - BUNDLES:

Bundles are available for all pages, if you need your js in only one page, to this:

Open your View, go to the bottom of the file and do this:

@section scripts{
    <script src="~/Scripts/js1.js"></script>
    <script src="~/Scripts/js2.js"></script>
    <script src="~/Scripts/js3.js"></script>
}

Things to keep in mind 2 - LAYOUT:

MVC works divides your content into 2 files, stuff common to all pages, like navigation bar, footer, css and js calls reside in:

Views -> Shared -> _Layout.cs

Views are the changeable content in the middle of the page, look for the method @RenderBody() in _Layout.cshtml to find where your view will be rendered.

Maybe you will have to divide your friend´s html to have some in _layout and some in the View. This is quite common.

Good luck and Happy Coding!!

Sign up to request clarification or add additional context in comments.

Comments

0

Sure,

Create an ../app folder and drop the js files

The html file you have, I suggest you copy paste its content into a razor view, ../Views/App/MyPage.cshtml

Then create a c# controller that will return that view AppController

public class AppController : Controller
   {
      public ActionResult MyPage()
      {
        return PartialView();
      }

Like this https://github.com/victorantos/AngJobs/blob/master/AngJobs/Controllers/AppController.cs

Another important note, make sure your router is configured properly, like this

https://github.com/victorantos/AngJobs/blob/master/AngJobs/App_Start/RouteConfig.cs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.