I have the following code in a MVC c# Razor view:
@{string url = "/Projects/_MonthRangesScriptsPartial";}
@using (Ajax.BeginForm(
  "_MonthRanges", 
  "Projects", 
  new { id = ViewBag.InputResourceID }, 
  new AjaxOptions { 
    HttpMethod = "POST", 
    UpdateTargetId = "MonthRanges", 
    InsertionMode = InsertionMode.Replace,
    OnComplete = "updategraphArrayScript(@url,@ViewBag.InputResourceID)"
  }))
The code works almost perfectly, but I would like to resolve the c# variables to their values in the OnComplete line.
That is to say, the Razor engin should resolve the code to (for example):
<form action="/Projects/_MonthRanges/55" 
  data-ajax="true" data-ajax-complete="updategraphArrayScript(/Projects/assets,55)"
  ...>
Rather than:
<form action="/Projects/_MonthRanges/55" 
  data-ajax="true" data-ajax-complete="updategraphArrayScript(@url,@ViewBag.InputResourceID)"
  ...>
Simply create another variable string:
@{
    string url = "/Projects/_MonthRangesScriptsPartial";
    string onComplete = String.Format("updategraphArrayScript({0}, {1})", url, ViewBag.InputResourceID);
}
@using (Ajax.BeginForm(
  "_MonthRanges", 
  "Projects", 
  new { id = ViewBag.InputResourceID }, 
  new AjaxOptions { 
    HttpMethod = "POST", 
    UpdateTargetId = "MonthRanges", 
    InsertionMode = InsertionMode.Replace,
    OnComplete = @onComplete
  }))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With