Having trouble with dynamic JavaScript onchange event not firing in my application. Here's the code snippet from my action result:
public ActionResult About()
{
ViewBag.Script = "<input type='text' name='myName' onchange='nameChange(this)' /><br/>" +
"<script type='text/javascript'>function nameChange(d){" +
"$('[name=myEmail]').val('');" +
"$.ajax({type: 'POST', url: '/Home/Search', data: '{name:d}', " +
"contentType: 'application/json; charset=utf-8', dataType: 'html'," +
"success: function(data) { $('[name=myEmail]').val(data.toString()); } });" +
"}</script>"
+ "<input type='text' name='myEmail' />";
ViewBag.Message = "Your application description page.";
return View();
}
This is how my controller looks like:
public ContentResult Search(string name)
{
return Content("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e9818c858586a98e84888085c78a8684">[email protected]</a>");
}
However, I'm facing an issue where the action URL is not being recognized. Can someone provide assistance with this problem?
Here's a part of the cshtml file:
@if (ViewBag.Script != null)
{
@Html.Raw(ViewBag.Script)
}