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
所以我已经尝试了一切,但我根本无法返回一个小的局部视图并将其放在div元素中。这是我的父视图
<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
我在.load()函数之前放了一些警告(“message”),它显示了一条消息,但后来我把它放在.load()之后,它没有显示它。我曾尝试使用和不使用html.raw()。这是我的控制器动作
public ActionResult doctorsview()
{
return PartialView("~/Views/_Doktor.cshtml", new Doktor());
}
Where am I wrong?
我哪里错了?
1 个解决方案
#1
16
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:
你不必传递HomeController的完整名称,在Url.Action()中我们必须传递Controller名称的前缀,当我们创建控制器时我们必须在mvc中添加一个Controller的后缀,当我们在帮助器中使用它时我们有只传递控制器名称没有控制器后缀:
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
你应该将它放在Controller的各个Views目录中,在这种情况下是Views - > Home
#1
16
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:
你不必传递HomeController的完整名称,在Url.Action()中我们必须传递Controller名称的前缀,当我们创建控制器时我们必须在mvc中添加一个Controller的后缀,当我们在帮助器中使用它时我们有只传递控制器名称没有控制器后缀:
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
你应该将它放在Controller的各个Views目录中,在这种情况下是Views - > Home