I am working with MVC4 Razor pages, in page I have one code block for jquery. In my script file I have one function like
fucntion MyAjaxRequest(ClickedElement, RequestType, RequestUrl, PostParentForm, PostformID,RequestData,ReturnFunction){}
from this function I send ajax request to call controller method. To specify which controller and controller method to be call I am passing value in RequestUrl parameter like
@section JSSection{
<script type="text/javascript">
$('.star-icon').click(function () {
MyAjaxRequest(this, 'get', 'Url.Action("MethodNameOfController", "ControllerName")', null, null, { EmailID: $(this).attr('value') },
function (result, clickedElement) {
if (result.ResponseData == "False") {
$(clickedElement).removeClass("star-icon stared").addClass("star-icon unstared");
}
else if (result.ResponseData == "True") {
$(clickedElement).removeClass("star-icon unstared").addClass("star-icon stared");
}
else {
}
});
});
</script>
}
but in this case its not working properly because I need to add @ before Url.Action(.... like
@section JSSection{
<script type="text/javascript">
$('.star-icon').click(function () {
MyAjaxRequest(this, 'get', '@Url.Action("MethodNameOfController", "ControllerName")', null, null, { EmailID: $(this).attr('value') },
function (result, clickedElement) {
if (result.ResponseData == "False") {
$(clickedElement).removeClass("star-icon stared").addClass("star-icon unstared");
}
else if (result.ResponseData == "True") {
$(clickedElement).removeClass("star-icon unstared").addClass("star-icon stared");
}
else {
}
});
});
</script>
}
but problem is that when I use @ in jquery code it will close section early before tag and not consider
);
</script>
}
Can anybody tell me how can I solve this?