Html.BeginForm将不会返回POST操作结果-RAZOR

cg91

我创建了一个视图以输入结果并将其反馈到控制器,在该控制器中可以将结果保存到数据库中,但是当我单击“提交”时,我将返回到GET actionresult结果,但我尝试将BeginForm放到内,但是它确实起作用通过将彼此相邻的所有输入文本框塞满,可以完全改变我的视图显示。如何保留现有布局并提交给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>      

`

杰米D77

你有两种形式,现在..你不能使用<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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章