我有一个反馈的下拉列表。按下保存按钮时我保存数据。我想在不使用保存按钮的情况下自动保存下拉列表,我该怎么做?这是我的控制器
public ActionResult SelectFeedBack(int id)
{
YelloAdminDbContext db = new YelloAdminDbContext();
ViewBag.FeedBack = new SelectList(db.FeedBack, "FeedBackId", "FeedBackDrpDown");
return PartialView();
}
[HttpPost]
public ActionResult SelectFeedBack(int FeedBack, int id)
{
YelloAdminDbContext db = new YelloAdminDbContext();
if (ModelState.IsValid)
{
var temp = db.FeedBack.Find(FeedBack);
db.SaveFeedBack.Add(new SaveFeedBack { LoginId = id, feedback = temp });
db.SaveChanges();
return JavaScript("alert ('success');");
}
return JavaScript("alert ('error');");
}
public ActionResult DisplayFeedBack(int id)
{
YelloAdminDbContext db = new YelloAdminDbContext();
var Feed = db.SaveFeedBack.Where(x => x.LoginId == id).FirstOrDefault();
if (Feed == null)
{
return Content("No Feed Back Entered");
}
return Content(Feed.feedback.FeedBackDrpDown);
}
我的观点是
@model MyYello.Admin.Models.FeedBack
@{
ViewBag.Title = "Feed Back";
}
<h2>Add Notes</h2>
@using (Html.BeginForm("SelectFeedBack", "Admin", FormMethod.Post))
{@Html.ValidationSummary(true);
<fieldset>
@Html.HiddenFor(item => item.FeedBackId)
<legend>Create Notes</legend>
<div class="editor-label">
@Html.LabelFor(item => item.FeedBackDrpDown)
</div>
@Html.DropDownList("FeedBack")
<p><input type="Submit" value="Save" id="Save" /></p>
</fieldset>
}
我如何在不使用按钮的情况下保存数据。