从视图表单提交控制器中的操作

时间:2018-01-18 17:12:00

标签: c# forms model-view-controller view controller

嗯,事情很简单,我有2个表格,一个显示一次,第二个显示当用户点击“添加新...”在第二个我有更多按钮,其中一个提交类型,做发布然后通过id / name将表单传递给控制器​​并创建一个对象personaje(字符),然后将其保存在实体中并更新数据库。

但是当激活按钮执行post动作时失败,得到错误404无法获取url但是我调用的动作不是视图:S

这是我的观看代码:

@{
if (ViewBag.opcionElegida == "personajes") //Se ha elegido el boton personajes, cargamos el apartado de personajes
{
    using (Html.BeginForm("Listar", "ModificarJuego", FormMethod.Post, new { name = "formLista_Personajes", id = "formLista_Personajes" }))
    {
        @Html.AntiForgeryToken()
        <br />
        <hr />
        <h2 style="text-align:center;">Personajes</h2>
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        if (Session["Editar"].ToString() != "Si")
        {
            <table class="table">
                <tr>
                    <th>Nombre</th>
                    <th>Apodo</th>
                    <th>Historia</th>
                    <th>Raza</th>
                    <th>Clase</th>
                    <th>Nivel</th>
                    <th>Exp</th>
                    <th>Oro</th>
                    <th>FUE</th>
                    <th>DES</th>
                    <th>INT</th>
                    <th>RES</th>
                    <th>AGI</th>
                    <th>VOL</th>
                    <th>SUE</th>
                    <th>Acciones</th>
                </tr>
                @foreach (var item in ViewBag.Informacion)
                {
                    <tr>
                        <td>@item.personaje_nombre</td>
                        <td>@item.personaje_apodo</td>
                        <td>@item.personaje_historia</td>
                        <td>@item.personaje_raza</td>
                        <td>@item.personaje_clase</td>
                        <td>@item.personaje_nivel</td>
                        <td>@item.personaje_exp</td>
                        <td>@item.personaje_oro</td>
                        <td>@item.personaje_fuerza</td>
                        <td>@item.personaje_destreza</td>
                        <td>@item.personaje_inteligencia</td>
                        <td>@item.personaje_resistencia</td>
                        <td>@item.personaje_agilidad</td>
                        <td>@item.personaje_voluntad</td>
                        <td>@item.personaje_suerte</td>
                        <td>
                            @Html.ActionLink("Editar", "Edit", new { id = item.idpersonaje }) |
                            @Html.ActionLink("Detalles", "Details", new { id = item.idpersonaje }) |
                            @Html.ActionLink("Eliminar", "Delete", new { id = item.idpersonaje })
                        </td>
                    </tr>
                }

            </table>
            @Html.ActionLink("Añadir nuevo", "AñadirNuevoPJ_Form")
        }
    }

    using (Html.BeginForm("AddNuevoPJ", "ModificarJuegoController", null, FormMethod.Post, new { name = "formAdd_Personajes", id = "formAdd_Personajes" }))
    {
        if (Session["Editar"].ToString() == "Si")
        {
            <table class="table">
                <tr>
                    <th>Nombre</th>
                    <th>Apodo</th>
                    <th>Historia</th>
                    <th>Raza</th>
                    <th>Clase</th>
                    <th>Nivel</th>
                    <th>Oro</th>
                    <th>FUE</th>
                    <th>DES</th>
                    <th>INT</th>
                    <th>RES</th>
                    <th>AGI</th>
                    <th>VOL</th>
                    <th>SUE</th>
                </tr>
                <tr>
                    <td>@Html.TextBox("txt_nombrePersonaje", "", new { @class = "form-control" })</td>
                    <td>@Html.TextBox("txt_ApodoPersonaje", "", new { @class = "form-control" })</td>
                    <td>@Html.TextArea("txt_historia", new { @class = "form-control", @onclick = "HistoriaZoom();", @onmouseout = "HistoriaZoomOut()", @onmouseover = "HistoriaZoom()", @style = "height:35px" })</td>
                    <td>@Html.DropDownList("raza_nombre", new SelectList(ViewBag.ListaRazas, "idraza", "raza_nombre"), new { @class = "form-control", @onchange = "CambioOpciones()", @style = "width:100px" })</td>
                    <td>@Html.DropDownList("clase_nombre", new SelectList(ViewBag.ListaClases, "idclase", "clase_nombre"), new { @class = "form-control", @onchange = "CambioOpciones()", @style = "width:110px" })</td>
                    <td>@Html.TextBox("txt_nivelPersonaje", "1", new { @class = "form-control", @style = "width:40px" })</td>
                    <td>@Html.TextBox("txt_oroPersonaje", "100", new { @class = "form-control" })</td>
                    <td><input type="text" id="txt_FUE" size="5" disabled="disabled" class="form-control" /></td>
                    <td><input type="text" id="txt_DES" size="5" disabled="disabled" class="form-control" /></td>
                    <td><input type="text" id="txt_INT" size="5" disabled="disabled" class="form-control" /></td>
                    <td><input type="text" id="txt_RES" size="5" disabled="disabled" class="form-control" /></td>
                    <td><input type="text" id="txt_AGI" size="5" disabled="disabled" class="form-control" /></td>
                    <td><input type="text" id="txt_VOL" size="5" disabled="disabled" class="form-control" /></td>
                    <td><input type="text" id="txt_SUE" size="5" disabled="disabled" class="form-control" /></td>
                </tr>
            </table>
            <div id="menuBottom">
                <ul>
                    <li><input type="submit" class="botonEnlace" value="Añadir_DeFormaCorrecta(NoFunciona)" onclick=""></li>
                    <li>@Html.ActionLink("Añadir_MedianteChapuza", "AñadirNuevoPJ")</li>
                    <li>@Html.ActionLink("Limpiar", "AñadirNuevoPJ_Form")</li>
                    <li><a href="#" onclick="window.history.go(-1);">Volver</a></li>
                </ul>
            </div>

        }
    }


}
else if..

这是我想在ModificarJuegoController.cs中调用的动作

[HttpPost]
    public AddNuevoPJ (string eleccionObjeto)
    {           
        return View();
    }

我得到的错误就是这个

  

错误de servidor enlaaplicación'/'。

     

没有se encuentra el recurso。

     

Descripción:HTTP 404. El recursoqueestábuscando(o una de sus depedencias)se puede haber quitado,haber cambiado de nombre o no estar disponible temporalmente。修改ladirecciónURLsiguienteyasegúresedequeestáescritacorrectamente。

     

DirecciónURLsolicitada:/ ModificarJuegoController / AddNuevoPJ

     

信息:VersióndeMicrosoft .NET Framework:4.0.30319; VersiónASP.NET:4.7.2110.0

我已尝试在提交按钮中使用OnCLick="'@Url.Action("AddNuevoPJ", "ModificarJuegoController")'

0 个答案:

没有答案
相关问题