0

I am using jQuery .load to call an action but it is not found.

This is because the production website url is different to dev url.

function ProjectChange() {
    var projid = $("input[name='ProjectLink']:checked").val();
    $("#documentList").load("/Home/GetDocumentList/",
                            { page: 0, projectid: projid },
                            LoadComplete);
}

I don't want to hard code the url in to the action call.

How do I inject "Url.Content" or something into this please?

Malcolm

2 Answers 2

1

Create a global javascript variable in your view containing the url:

<script type="text/javascript">
var documentListUrl = '<%= Url.Action("GetDocumentList", "Home") %>';
</script>

Then you could use this variable in your external javascript file:

$("#documentList").load(
    documentListUrl,
    { page: 0, projectid: projid },
    LoadComplete
);
Sign up to request clarification or add additional context in comments.

Comments

0

Is this what you wanted???

$("#documentList").load(
    '<%= VirtualPathUtility.ToAppRelative("~/Home/GetDocumentList") %>' ,
    { page: 0, projectid: projid }, LoadComplete);

It's not the nicest.

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.