gpt4 book ai didi

c# - 单个 MVC 页面上的多个表单

转载 作者:太空宇宙 更新时间:2023-11-03 18:07:18 25 4
gpt4 key购买 nike

下面是我的页面截图。它有 3 个选项卡 - 详细信息、用户和权限。每个选项卡都有自己的提交按钮,我需要在 Controller 中触发不同的代码(目前还没有代码)。

Screenshot of application

我的问题是,如何在单个 MVC 页面上有 3 个单独的表单,以及如何让每个提交按钮运行相应的代码?

查看

<div class="row-fluid">
<div class="span12">
<!-- BEGIN INLINE TABS PORTLET-->
<div class="widget">
<div class="widget-title">
<h4><i class="icon-user"></i></h4>
</div>
<div class="widget-body">
<div class="row-fluid">
<div class="span8">
<!--BEGIN TABS-->
<div class="tabbable custom-tab">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab_1_1" data-toggle="tab">Role Details</a></li>
<li><a href="#tab_1_2" data-toggle="tab">Users</a></li>
<li><a href="#tab_1_3" data-toggle="tab">Rights</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_1_1">
@using (Html.BeginForm("Details", "RoleController", FormMethod.Get, new { }))
{
@Html.ValidationSummary(true)
<div class="row-fluid">
<div class="span3">
@Html.HiddenFor(model => model.Id)
<div class="control-group">
<label class="control-label">@Html.DisplayNameFor(model => model.RoleName)</label>
<div class="controls controls-row">
@Html.EditorFor(model => model.RoleName)
@Html.ValidationMessageFor(model => model.RoleName)
</div>
</div>
<div class="control-group">
<label class="control-label">@Html.DisplayNameFor(model => model.Description)</label>
<div class="controls controls-row">
@Html.TextArea("Description", Model.Description, new { @cols = 400, @rows = 10 })
</div>
</div>
</div>
</div>
<input type="submit" class="btn btn-success" value="Save" />
}
</div>

<div class="tab-pane" id="tab_1_2">
@using (Html.BeginForm("UsersForRole", "RoleController", FormMethod.Post, new { }))
{
<!-- BEGIN DUAL SELECT-->
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTk5MjI0ODUwOWRkJySmk0TGHOhSY+d9BU9NHeCKW6o=" />
</div>
<div>
<table style="width: 100%;" class="">
<tr>
<td style="width: 35%">
<div class="d-sel-filter">
<span>Filter:</span>
<input type="text" id="box1Filter" />
<button type="button" class="btn" id="box1Clear">X</button>
</div>

<select id="box1View" multiple="multiple" style="height: 300px; width: 75%" runat="server">
</select><br />

<span id="box1Counter" class="countLabel"></span>

<select id="box1Storage">
</select>
</td>
<td style="width: 21%; vertical-align: middle">
<button id="to2" class="btn" type="button">&nbsp;>&nbsp;</button>

<button id="allTo2" class="btn" type="button">&nbsp;>>&nbsp;</button>

<button id="allTo1" class="btn" type="button">&nbsp;<<&nbsp;</button>

<button id="to1" class="btn" type="button">&nbsp;<&nbsp;</button>
</td>
<td style="width: 35%">
<div class="d-sel-filter">
<span>Filter:</span>
<input type="text" id="box2Filter" />
<button type="button" class="btn" id="box2Clear">X</button>
</div>

<select id="box2View" multiple="multiple" style="height: 300px; width: 75%;">
@foreach (var user in Model.Users)
{
<option>@Html.DisplayFor(model => user.SurnameFirstName)</option>
}
</select><br />

<span id="box2Counter" class="countLabel"></span>

<select id="box2Storage">
</select>
</td>
</tr>
</table>
</div>
<div class="mtop20">
<input type="submit" value="Submit" class="btn" />
</div>
<!-- END DUAL SELECT-->
}
</div>

<div class="tab-pane" id="tab_1_3">
@using (Html.BeginForm("RightsForRole", "RoleController", FormMethod.Post, new { }))
{
<table class="table table-striped">
<thead>
<tr>
<th>Right Name</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var right in Model.Rights)
{
<tr>
<td>@Html.DisplayFor(model => right.RightName)</td>
<td>@Html.DisplayFor(model => right.Description)</td>
<td>
<div class="success-toggle-button">
@Html.CheckBoxFor(model => right.Assigned, new { @class = "toggle" })
</div>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
</div>
<!--END TABS-->
</div>
<div class="span4">
<div class="control-group">
<label class="control-label">@Html.DisplayNameFor(model => model.DateCreated)</label>
<div class="controls controls-row">
@Html.EditorFor(model => model.DateCreated, new { @readonly = "readonly" })
</div>
</div>
<div class="control-group">
<label class="control-label">@Html.DisplayNameFor(model => model.CreatedBy)</label>
<div class="controls controls-row">
@Html.EditorFor(model => model.CreatedBy, new { @readonly = "readonly" })
</div>
</div>
<div class="control-group">
<label class="control-label">@Html.DisplayNameFor(model => model.LastUpdated)</label>
<div class="controls controls-row">
@Html.EditorFor(model => model.LastUpdated)
</div>
</div>
<div class="control-group">
<label class="control-label">@Html.DisplayNameFor(model => model.LastUpdateBy)</label>
<div class="controls controls-row">
@Html.EditorFor(model => model.LastUpdateBy)
</div>
</div>
</div>
</div>
</div>
</div>
</div>

UsersForRole Controller
[HttpPost]
public ActionResult UsersForRole(RoleModel model)
{
if (ModelState.IsValid)
{

}
return View(model);
}

最佳答案

我认为你可能在这行有问题:

 @using (Html.BeginForm("UsersForRole", "RoleController", FormMethod.Post, new { }))
Html.BeginForm 中的 Controller 名称应该只是 Role除非你的 Controller 名称是`Role Controller Controller?

关于c# - 单个 MVC 页面上的多个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24996327/

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