在的Razor视图ASP.Net MVC Ajax.BeginForm的onComplete通C#参数 [英] ASP.Net MVC Ajax.BeginForm OnComplete pass c# arguments in Razor view

查看:248
本文介绍了在的Razor视图ASP.Net MVC Ajax.BeginForm的onComplete通C#参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC C#的Razor视图下code:

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)"
  }))

在code作品几乎完美,但我想解决的的onComplete线C#的变量的值。

The code works almost perfectly, but I would like to resolve the c# variables to their values in the OnComplete line.

也就是说,剃刀ENGIN应该可以解决code到(例如):

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)"
  ...>

而不是:

<form action="/Projects/_MonthRanges/55" 
  data-ajax="true" data-ajax-complete="updategraphArrayScript(@url,@ViewBag.InputResourceID)"
  ...>

在先进的感谢,

Chopo

推荐答案

只需创建另一个变量字符串:

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
  }))

这篇关于在的Razor视图ASP.Net MVC Ajax.BeginForm的onComplete通C#参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆