哪里是我的"数据"在剃刀语法阿贾克斯的选择吗? [英] Where is my "data" Ajax option in Razor syntax?

查看:178
本文介绍了哪里是我的"数据"在剃刀语法阿贾克斯的选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档的https://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxoptions%28v=vs.118%29.aspx我找不到任何的数据参数,像

In the documentation https://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxoptions%28v=vs.118%29.aspx I can't find anything that is the equivalent of the data parameter in something like

$.ajax({
    url: '@Url.Action("AutoLocate")',
    type: 'GET',
    data: postData,
    success: function(result) {
        // process the results from the controller
    }
});

使用剃刀语法形式,例如。

Using Razor syntax for a form, e.g.

@using (Ajax.BeginForm("GenerateMasterLink", "SurfaceAssets", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "masterLinkHolder" })) { ... }

我怎么告诉它,我想要一个JavaScript变量,比方说,

how do I tell it that I want a JavaScript variable, say,

var str = "here's a string, bro!";

在要传递给相应的控制器

to be passed in to the corresponding controller

public ActionResult GenerateMasterLink (string str)
{
    ...
}

??????

??????

推荐答案

试试这个样子。

$.ajax({
url: '@Url.Action("AutoLocate")',
type: 'GET',
data: str,
success: function(result) {
    // process the results from the controller
}
});

和控制器

public ActionResult GenerateMasterLink (string str)
{
...
}

如果你有一个以上的参数,然后

If you have more than one parameter then

$.ajax({
url: '@Url.Action("AutoLocate")',
type: 'GET',
data: {id: 12,name:'Name'},
success: function(result) {
    // process the results from the controller
}
});

public ActionResult GenerateMasterLink (int id,string name)
{
...
}

这篇关于哪里是我的"数据"在剃刀语法阿贾克斯的选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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