9

so I've tried everything, but I simply can not return a small partial view and place it in div element. This is my parent view

<button id="doctors">Doktori</button>
<button id="apointments"> Pregledi</button>

 <div id="someDiv">
 </div>

<script>
    document.getElementById("doctors").onclick = function () { myFunction() };
    function myFunction() {

        $("#someDiv").load("@Html.Raw(Url.Action("doctorsview", "HomeController")) ")
    }
</script>

I put some alert("message") before .load() function, and it shows a message, but then I put it after .load(), it doesn't show it. I've tried with and without html.raw(). This is my controller action

public ActionResult doctorsview()
{
    return PartialView("~/Views/_Doktor.cshtml", new Doktor());        
}

Where am I wrong?

1 Answer 1

17

you don't have to pass complete name of HomeController, In Url.Action() we have to pass prefix of Controller name, when we create controller we have to add a postfix of Controller in mvc and when we use it in helpers we have to just pass Controller name without Controller postfix:

public class HomeController: Controller
{
public ActionResult doctorsview()
{
  return PartialView("~/Views/_Doktor.cshtml", new Doktor());        
}

}

Do like this:

$("#someDiv").load('@Url.Action("doctorsview","Home")');

and you should be placing it in respective Views directory of Controller, which is in this case Views -> Home

1
  • 1
    I'm dealing with this for couple of hours. Thanks a lot!
    – Alen Kopic
    Aug 25, 2014 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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