Jquery 在js对话框中重定向url(视图)
我有一个MVC3应用程序。我想显示我刚刚创建的结果 控制器和视图的一些代码Jquery 在js对话框中重定向url(视图),jquery,asp.net-mvc,json,wcf,Jquery,Asp.net Mvc,Json,Wcf,我有一个MVC3应用程序。我想显示我刚刚创建的结果 控制器和视图的一些代码 public ActionResult ViewGenerated(string Number, string ClientID) { // get a list of inmate id's and pins from batch number string url = HttpContext.Request.Url.ToString(); int clien
public ActionResult ViewGenerated(string Number, string ClientID)
{
// get a list of inmate id's and pins from batch number
string url = HttpContext.Request.Url.ToString();
int client;
client = int.Parse(ClientID);
int batch = int.Parse(Number);
var list = (from a in aContext.aDetail
select a).ToList();
// set this to the object collection
ViewBag.x = list;
return View();
}
然后查看
@foreach (var r in ViewBag.x)
{
<tr>
<td>@r.ID</td>
<td>@r.Name</td>
</tr>
我使用jquery对话框调用“GenerateX”
我不知道怎么做,我在这方面不是很强
非常感谢
更新:
$.getJSON('/Services/InService.svc/blah/GeneratePINs/').success(viewPins);
// return "Number" here and want to pass it to controller.
$(this).dialog('close'); // Close it
}
function viewPins(data) {
var clientId = $("#clientIds").val();
alert(clientId); // code not reach here
window.open('/WebAdminOrion/blah/ViewGeneratedPINs?Number=' + data + '?&ClientID=' + clientId);
}
您可以使用
窗口.location.href
前
或
见此:
HTML(对于javascript无阻碍):
我找到了答案
window.open('/WebAdminOrion/blah/ViewGeneratedPINs?Number=' + data + '&ClientID=' + clientId);
有一个问号。删除它,然后重新爱上它。假设服务返回一个整数,如何在js中获取它?您必须检查响应参数1 viewPins!=ViewPins javascript区分大小写,在“$(this.dialog('close');”什么是关闭?关闭jquery对话框后加上2“}”。我有一个按钮点击事件来调用这个函数。在javascript代码中,在哪里调用动作“ViewGenerated”?
window.location.href = '/controllername/actionname';
window.location.href = '@Url.Action("actionname")';
<!-- Constant or key in the "web.config" having the service route -->
<input type="hidden" id="service-url" value="@ConstUrlService" />
<input type="hidden" id="action-url" value="@Url.Action("action", "controller")" />
function GenerateX() {
var dialog = this;
// blah blah
$.getJSON($('#service-url').val(), function (response) {
/*
the call to "close" must be here, because the "ajax" is asynchronous
*/
/*
This answer has to be the number, and could have a response status
for example Ok (true/false)
*/
if (response.Ok && response.Number != 0) {
$(dialog).dialog('close'); // Close it
window.location = $('#action-url').val() + '?Number=' + response.Number + '&ClientID=' + response.ClientID;
}
else {
alert('problem');
}
}).fail(function() {
/*
for error
*/
alert('call error');
});
};
window.open('/WebAdminOrion/blah/ViewGeneratedPINs?Number=' + data + '&ClientID=' + clientId);