gpt4 book ai didi

c# - 根据 View 模型中的字符串更新内容

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:28 24 4
gpt4 key购买 nike

我正在运行一个 MVC 应用程序,它有一个像这样的 View 模型:

public class UserListViewModel
{
public UserListViewModel()
{
Users = new List<UserViewModel>();
QueriedUsers = new List<UserViewModel>();
}

public List<UserViewModel> Users { get; private set; }
public string SearchQuery { get; set; }
public List<UserViewModel> QueriedUsers { get; private set; }
}
  • 用户:原始用户
  • SearchQuery:由 View 返回的查询
  • QueriedUsers :用户排序后的用户

在我看来,我有以下代码:

@using (Html.BeginForm("Search", "EditUser"))
{
@Html.EditorFor(model => Model.SearchQuery);
}



@if (Model.QueriedUsers != null && Model.QueriedUsers.Any())
{
foreach (var u in Model.QueriedUsers)
{
// do stuff
}
}
else
{
foreach (var u in Model.Users)
{
// do stuff
}
}

这是 Controller 中的 HttpPost 代码:

[HttpPost]
public ActionResult Search(UserListViewModel input)
{
return View("EditUser",NewUserListModel(input));
}

在我点击搜索字段中的输入之前,我有一个这样的 URL:

http://localhost:61162/Admin/Users

点击进入后,我得到:

http://localhost:61162/Admin/Users/Search

从我的断点可以看出 Controller 代码正在运行。

我在新 URL 中得到的错误是:

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Admin/EditUser/Search

当然是url改了造成的

任何提示如何解决我的问题? :-) 我只是想在我的用户上有一个 where 子句,这样我就可以根据搜索输入显示相关数据。

最佳答案

来自@LarsHoldgaard 的最后评论:

Thanks a lot for your help, I got really confused with the project. However, the solution was changing the Search HttpPost to:

    return View("Index", NewUserListModel(input));

关于c# - 根据 View 模型中的字符串更新内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16168077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com