我在视图中有一个文本框和两个相同表单中的操作链接。我想要做的是,当我单击操作链接textbox value时,将在ActionResult中获得
Html.BeginForm("downloadpage","Finance"){
<div class="col-5">
<input type="text" class="form-control" name="txttitle" id="txtval" placeholder="E.g. PAK10NOV18" />
@Html.TextBox("first_name")
</div>
@Html.ActionLink("Download Master File", "get_master_file");
@Html.ActionLink("Download IBFT File", "get_ibft_file");
}
backend
public ActionResult get_master_file(string txttitle)
{
return View();
}
public ActionResult get_ibft_file(string txttitle)
{
return View();
}发布于 2019-02-07 19:01:43
为什么不使用jquery和ajax调用呢?
有一个按钮,当您单击该按钮时,将调用javascript函数。在这里,您可以获得输入值,如下所示:
var textvalue = $("#txtval").val();创建json,如下所示:
var json = '{txttitle: "' + textvalue + '"}';并调用您的控制器,如下所示:
$.ajax({
url:'@Url.Action("//Function", "//Controller")',
type:'POST',
data: json,
contentType:'Application/json',
success:function(result){
//Do nothing or do whatever you want
}
});https://stackoverflow.com/questions/54571384
复制相似问题