我正在使用C#razor引擎开发项目,我想知道是否可以将razor语法与jQuery合并。这可能吗?
我所采取的方法是这样的:
<script>
$(document).ready(function() {
@Html.Action("GoNext", "Actions", new { Id= ViewBag.Id, justifymessage = @:$("#msg").val(), Action = 3 })
});
</script>
答案 0 :(得分:1)
Razor是服务器端,而jQuery是客户端。你可以合并它们......你可能只在jQuery中编写一个剃刀代码,但是razor会在jQuery之前渲染它。
要从服务器调用操作,请使用Ajax。看看你能做什么
<script>
$(document).ready(function() {
var url="@Url.Action("GoNext","Actions", new {Id= ViewBag.Id, Action = 3 })";
url+="&justifymessage = "+$("#msg").val();
jQuery.get(url).done(function(htmls){
jQuery('#appendable').html(htmls);
});
});
</script>
<div id='appendable'></div>
答案 1 :(得分:0)
如果说,您想重定向到该网址,请尝试:
<script>
$(document).ready(function() {
var yoururl = "@Url.Action("GoNext", "Actions", new { Id= ViewBag.Id, justifymessage = "#param#", Action = 3 })";
location.href=yoururl.replace("#param#", $("#msg").val());
});
</script>