---
title: "Transfer view using javascript code to seprate js file in mvc"  
description: "Transfer view using javascript code to seprate js file in mvc"  
author: "Anonymous User"  
published: 2015-05-26  
updated: 2015-05-26  
canonical: https://www.mindstick.com/forum/23264/transfer-view-using-javascript-code-to-seprate-js-file-in-mvc  
category: "javascript"  
tags: ["mvc", "knockout.js"]  
reading_time: 1 minute  

---

# Transfer view using javascript code to seprate js file in mvc

I’m using [knockout.js](https://www.mindstick.com/forum/160797/conditional-html-heading-tag-based-on-variable-in-knockout-js) in my [asp.net mvc](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) I have [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) code

```
<script type="text/javascript">    var model = "@Html.Raw(Json.Encode(Model))";    $.get("@Url.Action("_CityPartial")"
...)   </script>
```

How to [transfer](https://www.mindstick.com/blog/11733/debt-management-for-startups-consolidation-loan-vs-balance-transfer) this javascript code in a separate [js file](https://www.mindstick.com/forum/12680/call-custom-js-function-inside-jquery-ajax-that-is-defined-in-an-external-js-file).

Please [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem) as soon as

Thanks in advance

## Replies

### Reply by Anonymous User

You can create external .js file with your code in and pass your serialized json object to it like this:

```
<script type="text/javascript">    var model = @Html.Raw(Json.Encode(Model));    DoThis(model);</script>
```

This has the benefits of keeping the main body of javascript in a separate file.

Any other razor variables can be passed across to the methods defined in the javascript in the same manor as the model has been above.


---

Original Source: https://www.mindstick.com/forum/23264/transfer-view-using-javascript-code-to-seprate-js-file-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
