- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个 View 来输入结果并反馈到 Controller ,在那里我可以将它们保存到数据库但是当我单击提交时,我返回到 GET actionresult 相反,我尝试将 BeginForm 放在里面并且它确实有效,但是它通过将所有输入文本框塞在彼此旁边来完全改变我 View 中的显示。如何保留我现有的布局并提交到 POST 操作结果?`
@{
ViewBag.Title = "CreateLecturer";
}
<br /><br /><br /><br />
<form class="form-horizontal">
@using (Html.BeginForm("CreateLecturer", "Admin", new { }, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<fieldset>
<legend>Add Lecturer</legend>
<div class="form-group">
<label for="addLect" class="col-lg-2 control-label">Lecturer Number</label>
<div class="col-lg-4">
<input type="text" class="form-control" id="addLect" name="addLect" placeholder="Lecturer Number">
</div>
</div>
<div class="form-group">
<label for="addLectFname" class="col-lg-2 control-label">Firstname</label>
<div class="col-lg-4">
<input type="text" class="form-control" id="addLectFname" name="addLectFname" placeholder="Firstname">
</div>
</div>
<div class="form-group">
<label for="addLectSname" class="col-lg-2 control-label">Surname</label>
<div class="col-lg-4">
<input type="text" class="form-control" id="addLectSname" name="addLectSname" placeholder="Surname">
</div>
</div>
<div class="form-group">
<label for="addLectPword" class="col-lg-2 control-label">Password</label>
<div class="col-lg-4">
<input type="password" class="form-control" id="addLectPword" name="addLectPword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
@Html.ActionLink("Cancel", "ViewLecturer", "Admin", null, new { @class = "btn btn-warning" })
<button type="reset" class="btn btn-default">Clear</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
}
</form>
`
最佳答案
你现在有两个表格..你不能使用 <form>
和 Html.BeginForm
一起。你需要使用一个或另一个。
尝试
@using (Html.BeginForm("CreateLecturer", "Admin", new { }, FormMethod.Post, new { @class="form-horizontal", enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<fieldset>
<legend>Add Lecturer</legend>
<div class="form-group">
<label for="addLect" class="col-lg-2 control-label">Lecturer Number</label>
<div class="col-lg-4">
<input type="text" class="form-control" id="addLect" name="addLect" placeholder="Lecturer Number">
</div>
</div>
<div class="form-group">
<label for="addLectFname" class="col-lg-2 control-label">Firstname</label>
<div class="col-lg-4">
<input type="text" class="form-control" id="addLectFname" name="addLectFname" placeholder="Firstname">
</div>
</div>
<div class="form-group">
<label for="addLectSname" class="col-lg-2 control-label">Surname</label>
<div class="col-lg-4">
<input type="text" class="form-control" id="addLectSname" name="addLectSname" placeholder="Surname">
</div>
</div>
<div class="form-group">
<label for="addLectPword" class="col-lg-2 control-label">Password</label>
<div class="col-lg-4">
<input type="password" class="form-control" id="addLectPword" name="addLectPword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
@Html.ActionLink("Cancel", "ViewLecturer", "Admin", null, new { @class = "btn btn-warning" })
<button type="reset" class="btn btn-default">Clear</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
}
您的另一个选择是删除 @using BeginForm
只需使用
<form class="form-horizontal" action="@Url.Action("CreateLecturer","Admin")" enctype="multipart/form-data" method="post">
</form>
关于Html.BeginForm 不会返回 POST actionresult - RAZOR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32589987/
我有一个 ActionResult 调用另一个 ActionResult。 我在我的 case 语句中调用了一个 ActionResult,但它不起作用。这是我所拥有的: public Acti
我有一个 ActionResult 扩展,它在返回页面时向 TempData 添加 toast: public static IActionResult WithMessage(this Action
假设我有以下代码,在记事本中模拟,所以请原谅任何小错误:) //Default page public ActionResult Index() { var musicView
我有一个来自数据库的对象,它在我的应用程序的很多地方使用。 实际的精确对象构建起来有点复杂,尤其是在开发过程中,我已经多次更改它。为此,我将方法从 Controller 中提取出来,并构建了一个具有对
我像这样向 GET ActionResult 发送参数: public ActionResult MyFormLetter(string studentName, string teacherName
在 Scott Hanselman 的书中(第 1 章),他为我们提供了两个选项来实现 Create 操作方法的 [HttpPost]。 第一个依赖于 TryUpdateModel 根据传入的表单字段
错误在下面代码的第 5 行: public class FirstController : Controller{ public async Task Index() {
我得到了简单的网络服务应用程序: public class MyController : Controller { public ActionResult balance( int amount)
所以我有这个 Javascript 代码: function AddToStuff(somethingID) { var stuffID = document.getElementById('
我试图在选中复选框时调用 ActionResult,但我不知道为什么它不起作用下面是我的代码。 --复选框 --模态
我正在使用 MVC 4 创建游戏。有一个犯罪功能,但我无法解决。我已经尝试了很多东西,但由于我是 MVC4 的新手,所以我无法弄明白。 我创建了一个单选按钮列表,每个不同的选项应该给出不同的结果。这是
我知道有很多类似的问题,但我没有在其中任何一个中得到我想要的答案。我想按原样将 ActionResult 转换为 String,方法如下: public ActionResult ProductDet
我想从一些操作方法中返回一个强制当前页面刷新的结果。 我写这篇文章是为了获得这样的结果: public class RefreshResult : ActionResult { pu
我使用 MVC 5 返回 Json。到达数据返回点的总时间为 40 毫秒。 然而,即使在服务器上运行它,浏览器也需要 6000 毫秒 才能获取数据。 我的问题是返回值后会发生什么。我正在尝试找出导致速
我创建了一个派生自 ActionResult 的 SitemapResult 类。它允许调用者添加任意数量的 URL 资源,然后以 XML 格式输出站点地图数据。 public class Sitem
例如,对于在线 Web 应用程序,我只需要服务器驱动器 X:\Docs 上文件夹中的文档。有没有一种方法可以让网站上的按钮默认打开 X:\Docs?我试过打开特定文件夹但没有成功: [HttpPost
我的 Controller 中有以下内容; public ActionResult CocktailLoungeBarAttendant() { return View
我是 MVC 的新手,正在尝试从 Controller 调用存储过程。 在模型中,我有 edmx,它将所有存储过程作为函数 Cannot implicitly convert type System.
这个有效: public ActionResult Edit(int id, CompPhone cmpPhn) { var vM = new MyViewModel(); if (cmpPh
假设我有应用程序 .net Core 2.1 Web API + Angular 7 为什么我应该总是返回 ActionResult? 这之间有什么区别吗: public ActionResult G
我是一名优秀的程序员,十分优秀!