我有一个MVC 5网站,它在网格中显示日志文件条目并提供搜索功能.我在索引页面上有搜索条件和grid.mvc网格.当用户输入搜索条件并单击提交按钮时,我希望ProcessLogEntries方法(如下所示)更新模型并刷新Index.cshtml页面 - 而不是导航到不存在的ProcessLogEntries页面!
基本上,我希望这个应用程序的行为类似于单页面应用程序......
如何设置HomeController.ProcessLogEntries()方法来完成此任务?
public class HomeController : Controller
{
public LogsResearchViewModel ViewModel { get; set; }
public HomeController()
{
ViewModel = new LogsResearchViewModel();
}
public ActionResult Index()
{
ViewBag.Message = "";
return View(ViewModel);
}
[HttpPost]
public ActionResult ProcessLogEntries(string txtSearchFor, string txtDateStart, string txtDateStop, string txtSource)
{
ViewBag.Message = "";
string searchFor = txtSearchFor.ToString();
DateTime start = DateTime.Parse(txtDateStart.ToString());
DateTime stop = DateTime.Parse(txtDateStop.ToString());
string source = txtSource.ToString();
ViewModel.GetProcessLogEntries(searchFor, start, stop);
ViewModel.GetErrorLogEntries(source, searchFor, start, stop);
return View(ViewModel);
}
}
Run Code Online (Sandbox Code Playgroud)