title: How to pass dynamic value in @Url.Action?
body: <p>I have written following jquery in my partial view:</p>
  
  <pre><code>    $.ajax({
          type: "POST",
          url: '@Url.Action("PostActionName", "ControllerName")',
          data: { Id: "01" },
          success: function(data)
              {
              if (data.success="true")
                  {
                      window.location = '@Url.Action("GetActionName", "ControllerName")'
                  }
              }
      });
  </code></pre>
  
  <p>The Action name and Controller name are not fixed, they are bound to change depending upon the view wherein this partial view is placed. I have functions to fetch invoking action and controller names, but not sure how I can pass them in @Url.Action.</p>
  
  <p>Following are Javascript functions to fetch action and controller names:</p>
  
  <pre><code>function ControllerName() {
              var pathComponents = window.location.pathname.split('/');
              var controllerName;
              if (pathComponents.length &gt;= 2) {
                  if (pathComponents[0] != '') {
                      controllerName = pathComponents[0];
                  }
                  else {
                      controllerName = pathComponents[1];
                  }
              }
              return controllerName;
          }
  
          function ActionName() {
              var pathComponents = window.location.pathname.split('/');
              var actionName;
              if (pathComponents.length &gt;= 2) {
                  if (pathComponents[0] != '') {
                      actionName = pathComponents[1];
                  }
                  else {
                      actionName = pathComponents[2];
                  }
              }
              return actionName;            
          }
  </code></pre>