1

My code looks like so:

@(Html.Kendo().DropDownList()
    .Name("MyDropDownList")
    .BindTo(new string[] { "StringOne", "StringTwo", "StringThree"})
    .Events(e => e.Change("MyDropDownListOnchange")))

In the scripts:

function MyDropDownListOnchange() {
    var val = $("#MyDropDownList").val();
    $("#LoadingDiv").load("Views/StringView/_StringOne.cshtml");

I have tried several variations:

  • "~/Views/......
  • "../Views/.....
  • "Views/....
  • "ImageView/....

Error:

//localhost:43222/Views/StringView/_StringOne.cshtml 404 (Not Found)

4
  • What is the absolute path to your file: //localhost:43222/??? Commented Sep 11, 2013 at 17:02
  • //localhost:43222/Views/StringView/_StringOne.cshtml Commented Sep 11, 2013 at 17:30
  • But it saying this file doesn't exists, so?... Commented Sep 11, 2013 at 17:33
  • Sry, thats what i assume it was when i pull the file into my Razor View it displays as follows <a href="~/Views/StringView/_StringOne.cshtml">~/Views/StringView/_StringOne.cshtml</a> but i have tried using /~/View Commented Sep 11, 2013 at 17:35

2 Answers 2

1

Try This way

function change() {
    var val = $("#OptionsDrop").val();

    //you will have to make a switch case here depending on how many options you have in the DDL

    $.ajax({
        url: '/StringView/GetStringOne',
        dataType: 'html',
        success: function (data) {
            $('#LoadingDiv').html(data);
        }
    });

This includes the controller

[HttpGet]
public PartialViewResult GetStringOne()
{
    return PartialView("_StringOne");
} 
Sign up to request clarification or add additional context in comments.

Comments

0
$("#LoadingDiv").load("Views/StringView/_StringOne.cshtml");

remove the .cshtml try this :

$("#LoadingDiv").load("Views/StringView/_StringOne");

and make sure in your controller you have returned this partial view

something like

[httpget]
public PartialViewResult _StringOne()
{
   return PartialView();
}

3 Comments

Same error GET http://localhost:59464/Views/StringView/_StringOne 404 (Not Found)
I added in the code for the controller, as per answer, changed the script to $("#LoadingPartialDataDiv").load("_" + val); wich equates to "_StringOne" still doesnt to find it.
Please take a look at the updated question above, I hvae rewrote some of your code, returns a different error.

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.