0

I am confuse how to achieve this

I have a external javascript file let say script.js and one <div> tag in HTML file. for example

<script src='script.js Full Path'></script>
<div id="div1">

</div>

Now, in my script.js file, i have ajax get function which calls Controller Action like below

 $(function () {

 var url = 'http://www.example.com/controller/GetHTML';
   $.get(url, function (data) {

        $('#div1').html(data);

    });
 });

 and Controller Action is

  public ActionResult GetHTML()
    {
        return View();
    } 

  and view for GetHTML Action is 

    @{
    ViewBag.Title = "GetHTML";
    Layout = null;
     }

   <h2>This is HTML View</h2>

Now, i want render View as HTML in to div1, Even if i am not sure it's possible or not

So, Please any guys can help me to achieve above, it will really help me a lot.

5
  • 1
    What issue you are facing? Above statement you've added will surely fullfill your requirement Commented Jun 14, 2013 at 8:00
  • But i am not getting any response as html in div1 i don't know whats the problem.. Commented Jun 14, 2013 at 8:31
  • Try to alert the data and let me know the output. and also please paste your action method code as well Commented Jun 14, 2013 at 8:33
  • @KD i have edited the question.. please suggest Commented Jun 14, 2013 at 8:55
  • Check this url var url = "example.com/controller/GetHTML"; You havn't added controller name here Commented Jun 14, 2013 at 8:56

1 Answer 1

1

Enter your URL Correctly... The controller name is missing i think

$(function () {

 var url = 'http://www.example.com/YOUR_CONTROLLER_NAME/GetHTML';
   $.get(url, function (data) {
        alert(data);
        $('#div1').html(data);

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

3 Comments

No i am giving correct url, if i access the url in browser the view renders correct as "This is HTML View" in browser. but i want this html in my div1 and i have a separate HTML file containing div1 and script.js as mention in question.
I hope you are not having Cross domain calls by d way :)
I think you are right!! we need either JSON or XML data type in response... and thanks for you time and support.

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.