Mvc将ID传递给控制器而没有形式。 [英] Mvc pass ID to controller without form.
问题描述
亲爱的朋友们,
我正在寻找以下内容;
我有一个带有URL.Action的href。
@ Url.Action(Index,Action,new {ID = 1})
ID需要是输入字段的隐藏值。
< input type =textstyle =visibility:hidden; class =SelectedActionvalue =/>
此隐藏输入字段的值用jquery填充。我不想创建一个表单,所以想知道如何将隐藏输入的值输入到de URL.Action ID。
没有表单的任何选项吗?使用jquery或javascript。
Ajax提交我发现的唯一选项。
Dear friends,
I was searching for the following;
I have a href which got a URL.Action.
@Url.Action("Index", "Action", new { ID = 1 })
The ID need to be hidden value from a input field.
<input type="text" style="visibility:hidden;" class="SelectedAction" value=""/>
The value of this hidden input field is filled with jquery. I don't want to create a form so wondering how I can get the value of the hidden input into de URL.Action ID.
Any options to do this without a form? using jquery or javascript.
Ajax submit the only option so far I found.
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<input type="button" value="Send" onclick="submit()" />
</div>
<script>
function submit() {
$.ajax({
url: @Url.Action("act", "con") + '?param1=' + $('#myFormSubmit').value +
'¶m2=' @Model.Obj.Value1 +
'¶m3=' + @Model.HashedValue,
type: 'POST',
// ... other ajax options ...
});
}
这是唯一的选择吗?
This is the only option?
推荐答案
.ajax({
url:@ Url.Action(act,con)+'?param1 ='+
.ajax({ url: @Url.Action("act", "con") + '?param1=' +
('#myFormSubmit')。value +
'& param2 ='@ Model.Obj.Value1 +
'& param3 ='+ @ Model.HashedValue,
type:'POST',
// ......其他ajax选项......
});
}
('#myFormSubmit').value + '¶m2=' @Model.Obj.Value1 + '¶m3=' + @Model.HashedValue, type: 'POST', // ... other ajax options ... }); }
这是唯一的选择吗?
This is the only option?
如你所说,隐藏使用jQuery填充输入值,您可以执行以下操作:
As you said, hidden input value is filled using jQuery, you can do the following:
@Url.Action("Index", "Action", new { @class = "myLink" });
<input type="text" style="visibility:hidden;" class="SelectedAction" />
这篇关于Mvc将ID传递给控制器而没有形式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!