Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

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.

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

1 Answer 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);

    });
 });
share|improve this answer
    
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. – Hitesh Bavaliya Jun 14 '13 at 9:00
    
What it shows if you alert the data? – K D Jun 14 '13 at 9:01
    
nothing should getting in alert :-( – Hitesh Bavaliya Jun 14 '13 at 9:02
1  
I hope you are not having Cross domain calls by d way :) – K D Jun 14 '13 at 9:15
    
I think you are right!! we need either JSON or XML data type in response... and thanks for you time and support. – Hitesh Bavaliya Jun 14 '13 at 9:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.