0

i'm trying to launch a new preview page, for this i'm trying to call when we click on the image. And also i need to pass a ID as parameter to the new page. & i want to receive it in public ActionResult Index method. Here is the code which i have tried.

From parents index.aspx

<a href="#" onclick="openWindow('Preview/Index.aspx?ID = 12344');"><img style="border:0;" src="/Content/Images/approveIcon.png" alt="HTML try" width="20" height="20" /></a>


<script language='Javascript'>
<!--
    // Function to open new window containing window_src, 100x400
    function openWindow(window_src) {
        window.open(window_src, 'newwindow', config = 'height=100, width=400, '
        + 'toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, '
        + 'directories=no, status=no');
    }
-->
</script>

Here is my new preview controller class

public class PreviewController : Controller
{
    //
    // GET: /Preview/

    public ActionResult Index(String ID)
    {
        return View();
    }

}

I'm getting resource missing error, How to launch new preview window and pass ID as parameter to index method?

kloarubeek
  • 2,706
  • 20
  • 24
Naruto
  • 9,476
  • 37
  • 118
  • 201
  • check the url that it is trying to open using fiddler or the network tab in the developers tools on the browser. It may be an incorrect url – Nathan Fisher Apr 16 '14 at 06:07
  • i'm not getting your syntax. what is that window.location.pathname? where i need to put that, could you please tell in brief, i'm new to this – Naruto Apr 16 '14 at 06:08
  • Try using a '/' in front of url like '/Preview/Index.aspx?ID=12344' without space between parameter and value – Kira Apr 16 '14 at 07:06

2 Answers2

0

I hope it will help: in your link

<a href="#" onclick="openWindow(@Url.Action("Index", "Preview", new { id = "1234" });"><img style="border:0;" src="/Content/Images/approveIcon.png" alt="HTML try" width="20" height="20" /></a>

And in your script

<script language='Javascript'>
 <!--
// Function to open new window containing window_src, 100x400
  function openWindow(window_src) {
    var path = window.location.pathname + window_src;
    alert(path);//So you can see the full path
    window.open(path , 'newwindow', config = 'height=100, width=400, '
    + 'toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, '
    + 'directories=no, status=no');
  }
-->
  • Hi, i'm getting error in IE like "Message: Conditional compilation is turned off". And also page is still not opening – Naruto Apr 16 '14 at 06:34
  • is it possible to use `alert(path)` before `Window.open` so you can see the path –  Apr 16 '14 at 06:42
0
function openWindow(srcid) {
$.ajax({
    url: 'Preview/Index',
    type: "POST",
    dataType: "json",
    data: { ID: 12344},
    success: function (data) {
       alert(error.toString());
    },
    error: function (error) {

        alert(error.toString());
    }
});

}

<a href="#" onclick="openWindow();"><img style="border:0;" src="/Content/Images/approveIcon.png" alt="HTML try" width="20" height="20" /></a>
Nayeem Mansoori
  • 821
  • 1
  • 15
  • 41