如何将价值从视图传递到控制器

问题描述:

在控制器我有功能public ActionResult Index(int id,int test= 0,int to=10){}我试图改变价值测试从单击视图获取测试+ = 10,但我不知道如何。我尝试了与行动链接和ajax,但它不工作。有任何想法吗? 我的查看码:如何将价值从视图传递到控制器

<html ng-app> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
    <title>Countries</title> 
    <link href="~/Content/style.css" rel="stylesheet" /> 
    <link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" /> 

</head> 
<body> 
    <div> 
     <table> 
      <tr> 
       <td><h3>Matches</h3></td> 
      </tr> 
      <tr> 

      </tr> 
      @foreach (var i in Model.ListMatch) 
      { 

       <tr> 
        <td>@Html.ActionLink(i.Description, "", new { id = i.Id })</td> 

       </tr> 




      } 

     </table> 
    </div> 
</body> 
</html> 

我将结果返回到ng-view。我可以这样做

<a href="@Url.Action("Index", "Countries",new { id = i.Id, from+=10 })"></a> 
+0

请显示您的查看代码。 – Robert 2015-02-10 15:01:09

+0

有我的看法代码 – None 2015-02-10 15:06:03

+0

你想添加10到服务器的每次调用中的变量吗? – AnotherGeek 2015-02-10 17:52:57

这个问题是不是很好的解释,但是从我猜想你要能够做出改变的值,而不重新加载页面或退出了这一观点。

为了做到这一点,你必须使用AJAX。我知道你说过你尝试过AJAX,但也许你错了。试试这个:

$('#yourbutton').click(function() { 
    $.post("/YourController/YourFunction", function() { 
     alert("success"); 
    }); 
});