Asp.net mvc 在视图上的现有表中插入新行

Asp.net mvc 在视图上的现有表中插入新行,asp.net-mvc,html-table,Asp.net Mvc,Html Table,这是视图中的我的表(cshtml): 现在我想将结果附加到表tblketquatk中,是否仍然可以不使用Javascript执行此操作 在使用JQuery之前,我已经完成了这项工作,JQuery将使用Ajax将结果附加到现有表中,而无需重新加载页面 链接到以获得更好的外观 我想要的是如何将新返回的数据集插入表中,并且表单上的参数保持不变/重置 非常感谢您的帮助 您需要绑定到模型,以便模型可以返回到视图中 public class SearchViewModel { public int Da

这是视图中的我的表(cshtml):

现在我想将结果附加到表tblketquatk中,是否仍然可以不使用Javascript执行此操作

在使用JQuery之前,我已经完成了这项工作,JQuery将使用Ajax将结果附加到现有表中,而无需重新加载页面

链接到以获得更好的外观

我想要的是如何将新返回的数据集插入表中,并且表单上的参数保持不变/重置


非常感谢您的帮助

您需要绑定到模型,以便模型可以返回到视图中

public class SearchViewModel
{
  public int Days { get; set; }
  ....
}

public class MainViewModel
{
  public SearchViewModel Search { get; set; }
  // Add a property for the collection of items you are rendering in the table
}
看法


由于表单属性现在已绑定到模型并返回该模型,因此返回视图时将保留这些值。

返回视图的是什么模型?您需要传递一个集合,然后通过该集合循环创建每一行。您可以停留在同一页面上并从服务器追加数据的唯一方法是使用ajax,因此没有javascript是不可能的。否则,您需要以正常提交方式发布这些值,并返回一个呈现新值的全新页面table@StephenMuecke我明白了,你能告诉我如何用新结果呈现新页面,并且参数保持不变吗?参数保持不变是指,用新项呈现表吗您在控制器中以及提交之前显示的现有项?您需要使用模型并绑定到该模型(两种方式),以便在返回视图时“保留”值。我使用partialview创建了该视图,并且模型同时包含参数和结果数据集。无论如何谢谢你!给猫剥皮的方法很多。很好,你自己解决了:)
    [HttpPost]//Run action method on form submission
    public ActionResult LastTwoSubmit(string cityID, string numbers, int days, bool onlySpecial)
    {
        // get the result from sql server based on the parameters 
        // now i want to append the result to the table tblketquatk
        return View();
    }
public class SearchViewModel
{
  public int Days { get; set; }
  ....
}

public class MainViewModel
{
  public SearchViewModel Search { get; set; }
  // Add a property for the collection of items you are rendering in the table
}
@model MainViewModel
@using (Html.BeginForm())
{
  @Html.TextBoxFor(m => m.Search.Days)
  ....
  <input type="submit" ... />
}
// add loop to create table rows
[HttpPost]
public ActionResult LastTwoSubmit(MainViewModel model)
{
  // use the values of model.Search to query the database and add to the model collection
  return View(model);
}