0

I am new to ASP MVC I have retrieved some data from database. I want to pass that variable to JavaScript file.

my controller code :

 using (issue_management_systemEntities db = new issue_management_systemEntities())
        {

            var lineInfo = db.line_supervisor.Where(x => x.supervisor_emp_id == 1).FirstOrDefault();
            var mapInfo = db.line_map.Where(y => y.line_id == lineInfo.line_line_id).FirstOrDefault();
            return View();
        }

I want to pass mapInfo.map variable to js file as this

var mapext = 'mapInfo.map'  

how can I do that?

2

1 Answer 1

0

Since you're not binding a model to the view, you could store the data in a viewbag;

ViewBag.mapInfo = db.line_map.Where(y => y.line_id == lineInfo.line_line_id).FirstOrDefault();

Then on the script part of your view file;

var mapext = '@ViewBag.mapInfo';
Sign up to request clarification or add additional context in comments.

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.