我按照這個例子,使N至N關係如何獲取視圖的文本框?在我的控制器
它做工精細,但對於N到N的關係與有效載荷到數據庫中,我找出我可以做[HTTPGET]並顯示我想要顯示的視圖,但現在我想知道如何獲得我在視圖中的文本框,我可以在我的控制器中看到複選框(請參閱下面的操作),這是我的視圖,所以我的問題將如何獲得文本框?在我的每個複選框的控制器?
@using (Html.BeginForm("AgregarEmpresas", "Empleado"))
{
<fieldset>
<div class="editor-field">
<table>
<tr>
@{
int cnt = 0;
List<ITCOrganigrama.ViewModel.AsignarEmpresa> empresas = ViewBag.Empresas;
foreach (var empresa in empresas)
{
if (cnt++ % 5 == 0) {
@: </tr> <tr>
}
@: <td>
<input type="checkbox"
name="selectedEmpresa"
value="@empresa.EmpresaId"
@(Html.Raw(empresa.Assigned ? "checked=\"checked\"" : "")) />
@empresa.Nombre
<div>
@Html.LabelFor(model => empresa.cargo)
@Html.TextBoxFor(model => empresa.cargo, new { style = "width: 150px;" })
@Html.ValidationMessageFor(model => empresa.cargo)
</div>
@:</td>
}
@: </tr>
}
</table>
</div>
<p>
<input type="submit" value="Agregar" />
</p>
</fieldset>
}
在那裏我得到chekbox行動
[HttpPost]
public ActionResult AgregarEmpresas(int? id, FormCollection formCollection, string[] selectedEmpresa)
{
}
我最後的觀點: http://s3.subirimagenes.com:81/otros/previo/thump_7406511add1.jpg http://www.subirimagenes.com/otros-add1-7406511.html
編輯:
ViewModel類
public class AsignarEmpresa
{
public int EmpresaId { get; set; }
public string Nombre { get; set; }
public string cargo { get; set; }
public bool Assigned { get; set; }
}
一個在我的行動中,我得到空empresaTextBox 我在我的viewmodel有一個類與布爾和字符串 – 2012-02-06 18:33:03