我有一个文本框和按钮,当用户输入一个值并按下提交按钮时,我需要在同一视图中的 Kendo UI Grid 中显示该值..
为此,我这样做了......
这是我的模型。。
namespace KendoSampleMVCApp.Models
{
public class TextBoxGrid
{
public string EnteredValue { get; set; }
public List<EmployeeDetails> employees;
}
public class EmployeeDetails
{
public string EmployeeId { get; set; }
public string ManagerId { get; set; }
}
}
这是我的控制器
namespace KendoSampleMVCApp.Controllers
{
public class EnterValuesGridController : Controller
{
public ActionResult Index( TextBoxGrid model)
{
return View(GetEmployee());
}
[HttpPost]
public ActionResult PostValues(TextBoxGrid model)
{
TempData["enteringValue"] = model.EnteredValue;
return View(model);
}
public IEnumerable<EmployeeDetails> GetEmployee()
{
string enteredValueId =(string) TempData["enteringValue"];
string managerId = "M" +enteredValueId;
List<EmployeeDetails> empdtls = new List<EmployeeDetails>();
EmployeeDetails em1 = new EmployeeDetails();
em1.EmployeeId = enteredValueId;
em1.ManagerId = managerId;
empdtls.Add(em1);
return empdtls;
}
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
{
return Json(GetOrders().ToDataSourceResult(request));
}
private IEnumerable<EmployeeDetails> GetOrders()
{
return GetEmployee();
}
}
}
这是我的观点
@model KendoSampleMVCApp.Models.TextBoxGrid
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm("PostValues","EnterValuesGrid",FormMethod.Post))
{
<div>
<fieldset>
<legend>Enter Textbox Value</legend>
<div class="editor-field">
@Html.TextBoxFor(m=>m.EnteredValue)
</div>
<p>
<input type="submit" name="Submitbutton1" value="Submit1" />
</p>
</fieldset>
</div>
}
@model IEnumerable<KendoSampleMVCApp.Models.EmployeeDetails> <----- error at this line
<h2>Index</h2>
@using (Html.BeginForm())
{
@(Html.Kendo().Grid<KendoSampleMVCApp.Models.EmployeeDetails>()
.Name("grid")
.Columns(columns => {
columns.Bound(p => p.EmployeeId).Filterable(false).Width(100);
columns.Bound(p => p.ManagerId).Filterable(false).Width(100);
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Orders_Read", "EnterValuesGrid"))
)
)
}
我在这条线上遇到错误,@model IEnumerable<KendoSampleMVCApp.Models.EmployeeDetails>
说
解析器错误消息:文件中只允许使用一个“模型”语句。
请任何人提出任何想法为什么我会收到此错误...我不能在同一视图中使用两个模型...。
非常感谢 ...
编辑:我可以在我的模型中这样做吗...
public class ParentViewModel
{
public EmployeeDetails EmployeeDetails { get; set; }
public TextBoxGrid TextBoxGrid { get; set; }
}