asp.net - 返回视图()不重定向页面
问题描述
我有两种方法。我用 Ajax 调用了 GetApps 方法。此外,Getapps 重定向到 Apps 方法。但是,“return view()”命令不起作用。它不会重定向到页面。我的错在哪里?
public IActionResult Apps(ApplicationViewModel model)
{
var apps = JsonSerializer.Deserialize<List<ApplicationViewModel>>(TempData["Applicaitons"].ToString());
return View("/Home/Apps", apps);
}
[HttpPost]
public IActionResult GetApps(string customerId)
{
ApplicationResponse apps = new ApplicationResponse();
var result = _dashboardService.GetApp(Guid.Parse(customerId));
apps.Applications = result.Result.Data.Applications;
TempData["Applicaitons"] = JsonSerializer.Serialize(apps.Applications);
return RedirectToAction("Apps", "Home", new { model = apps.Applications });
}
解决方案
在这种情况下,我认为使用 ajax post 会破坏重定向,我不知道怎么做,但我有一个解决方案
您可以使用 windows.location.href 而不是 ajax 调用发送参数。
function GetApps() {
var customerId = localStorage.getItem('CustomerId');
var url = window.location.href
url = '/home/apps?customerId=' + customerId;;
window.location.href = url;
}
您可以使用 actionresult 中的参数进行操作,并将模型返回到其中查看。
public IActionResult Apps(string customerId)
{
ApplicationResponse apps = new ApplicationResponse();
var result = _dashboardService.GetApp(Guid.Parse(customerId));
apps.Applications = result.Result.Data.Applications;
return View(apps.Applications);
}
推荐阅读
- java - 在索引中找不到生产者方法返回类型:org.springframework.web.client.RestTemplate
- azure-devops - 需要通过 azure 管道将每个阶段的发布工件存储在单个目录中
- github - 引用 README.md 中显示的图像
- python - Kivy 计算按下“计数器”按钮时打开的 ToggleButtons 的数量
- php - PHP ODBC一次将多行插入MSSQL返回错误
- javascript - 如何使用 Jquery 读取默认值?
- java - 如何将arrayist作为mapreduce java的输入
- ruby-on-rails - 安装 Rails 4.2.5 时出错,mkmf.rb 找不到 ruby 的头文件
- flutter - Flutter // 点击按钮使用 async 执行两个函数并等待函数 onPressed 并从 api 获取数据
- jmeter - 从 JMeter 中的 CSV 数据集配置中随机选择