Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Is there a way to pass back a url using ajax/json

$
0
0

So I have a url stored in a database and I need to render that URL on the  an MVC razor view along with other information.

Currently I am able to get the data back from the mvc crontroller using the follow

The Ajax/json stuff

        function ValidateContestant(Contestant_ID)
        {
            //Get Contestant/Candidate Bio-Info to display on screen storing the ID To the Record


            //Contestant_ID = Contestant_ID || 0;

            var data = { Contestant_ID: $('#JWS_CANDIDATE_ID').val() };$.ajax
                (
                    {
                        url: '@Url.Action("ValidateContestant","JWS")',
                        type: 'POST',
                        DataType: 'Json',
                        contentType: 'application/json; charset=utf-8',
                        traditional: true,
                        data: JSON.stringify(data),
                        success: function (data)
                        {$('#CANDIDATE_DETAILS').html(""); //Clear Old Value$('#CANDIDATE_DETAILS').val(data); //Clear Old Value$('#lblCandidate').show();$('#CANDIDATE_DETAILS').show();
                        }

                    }

                )

        }

The Mvc Controller actionresult that gets called

  [HttpPost]
        public ActionResult ValidateContestant (int Contestant_ID)
        {
            string ContestantData = "";

            var Results = db.CM_CONTESTANTS_MASTER_DETAIL_TBL.FirstOrDefault(c => c.MC_CONTESTANT_ID == Contestant_ID);

            var sb = new StringBuilder();

            sb.Append(Results.MC_CONTESTANT_FIRST_NAME.ToString() + " " + Results.MC_CONTESTANT_LAST_NAME.ToString());
            sb.AppendLine();
            sb.Append(Results.MC_CONTESTANT_DOB.ToString());
            sb.AppendLine();
            sb.Append(Results.MC_CONTESTANT_VIDEO_FILE.ToString());
            ContestantData = sb.ToString();
            return Json(ContestantData);

        }

Or is there a way to call a second function  from the ajax function? In the second function I can get the URL and pass it back to the view by itself but its is all triggered by data input in one field on the MVC view

        [HttpPost]
        public ActionResult GetContestantVideoLink(int Contestant_ID)
        {

            //GET video link and turn it to url in view
            //see:https://stackoverflow.com/questions/16921481/how-do-i-pass-a-link-through-viewdata-in-mvc-4

            var Results = db.CM_CONTESTANTS_MASTER_DETAIL_TBL.FirstOrDefault(c => c.MC_CONTESTANT_ID == Contestant_ID);

            string VideoLink = Results.MC_CONTESTANT_VIDEO_FILE.ToString();

            ViewData["CVideoLink"] = VideoLink;

            return View();

        }

The goal is to have it so the URL stored in the database is clickable from the mvc view.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>