gpt4 book ai didi

Html.BeginForm 不会返回 POST actionresult - RAZOR

转载 作者:行者123 更新时间:2023-11-27 23:38:57 29 4
gpt4 key购买 nike

我创建了一个 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com