[英]In razor view, how to pass model property to JavaScript function and display return value?
I have a partial view that is rendered multiple times from a foreach loop in the parent view. 我有一个局部视图,该局部视图从父视图的foreach循环中多次渲染。
I need to take a model property value (string), pass it to a javascript function to do some checking and possible processing, string manipulation etc., and then return the value to the razor view for display, likely using @Html.Raw. 我需要获取模型属性值(字符串),并将其传递给javascript函数进行一些检查和可能的处理,字符串操作等,然后将该值返回到剃刀视图以进行显示,可能使用@ Html.Raw。
Can anyone suggest how to accomplish this, and is this the appropriate approach for this problem (this has to be done on the client)? 任何人都可以建议如何做到这一点,这是否是解决此问题的适当方法(必须在客户端上完成)? Thank you. 谢谢。
Im not sure but, you can try something like this! 我不确定,但是您可以尝试类似的方法!
<script>
$(function() {
var jsVar = @Model.Text; //It works, just the editor shows an error.
//Do your Stuff with jsVar;
$('#txtExample').prop('value', jsVar); //write it back!
});
</script>
@Html.TextBoxFor(e => e.Text, new {id = "txtExample"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.