Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用编辑时使我的表单自动填充_C#_Asp.net Mvc_Razor_Edit - Fatal编程技术网

C# 使用编辑时使我的表单自动填充

C# 使用编辑时使我的表单自动填充,c#,asp.net-mvc,razor,edit,C#,Asp.net Mvc,Razor,Edit,对mvc来说非常陌生。我的问题是,当我有一条记录要编辑时,我的视图不会自动填充表单。具体来说,我正试图进入一个拍卖网站出价。我希望其他一切保持不变,只更新出价。如果我的表单没有自动填充,那么所有内容都将为空。任何帮助都将不胜感激 这是来自CarAuctionController的 //获取:制作/编辑/5 公共操作结果编辑(int id=3) { CarList CarList=db.CarLists.Find(id); 返回视图(); } //发布:制作/编辑/5 [HttpPost] 公共

对mvc来说非常陌生。我的问题是,当我有一条记录要编辑时,我的视图不会自动填充表单。具体来说,我正试图进入一个拍卖网站出价。我希望其他一切保持不变,只更新出价。如果我的表单没有自动填充,那么所有内容都将为空。任何帮助都将不胜感激

这是来自CarAuctionController的
//获取:制作/编辑/5
公共操作结果编辑(int id=3)
{
CarList CarList=db.CarLists.Find(id);
返回视图();
}
//发布:制作/编辑/5
[HttpPost]
公共行动结果编辑(CarList CarList)
{
尝试
{
//TODO:在此处添加更新逻辑
if(ModelState.IsValid)
{
db.Entry(carlist.State=EntityState.Modified;
db.SaveChanges();
返回操作(“索引”);
}
返回视图(“索引”);
}
抓住
{
返回视图();
}
}
这是来自view Edit.cshtml的
@模型ClassicRaction.CarList
@{
ViewBag.Title=“编辑”;
}
编辑
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
卡利斯特

@Html.ValidationSummary(true,“,new{@class=“text danger”}) @Html.HiddenFor(model=>model.ID) @LabelFor(model=>model.ModelYear,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.ModelYear,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.ModelYear,“,new{@class=“text danger”}) @LabelFor(model=>model.Make,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Make,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Make,“,new{@class=“text danger”}) @LabelFor(model=>model.model,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.model,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.model,“,new{@class=“text danger”}) @LabelFor(model=>model.Description,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Description,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Description,“,new{@class=“text danger”}) @LabelFor(model=>model.CarImage,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.CarImage,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.CarImage,“,new{@class=“text danger”}) @LabelFor(model=>model.DatePosted,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.DatePosted,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.DatePosted,“,new{@class=“text danger”}) @LabelFor(model=>model.AuctionEndDate,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.AuctionEndDate,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.AuctionEndDate,“,new{@class=“text danger”}) @LabelFor(model=>model.ReserveBid,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.ReserveBid,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.ReserveBid,“,new{@class=“text danger”}) @LabelFor(model=>model.PosterUserID,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.PosterUserID,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.PosterUserID,“,new{@class=“text danger”}) @LabelFor(model=>model.ViewingLocation,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.ViewingLocation,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.ViewingLocation,“,new{@class=“text danger”}) @LabelFor(model=>model.HighestBid,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.HighestBid,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.HighestBid,“,new{@class=“text danger”}) @LabelFor(model=>model.HighBidUserId,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.HighBidUserId,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.Hi)
return View("Index");
return View("Index", carlist);
// GET: CarAuction/Edit/5
public ActionResult Edit(int id= 3)
{

    CarList carList = db.CarLists.Find(id);

    // Change this:
    return View(carList);
}