簡體   English   中英

MVC ASP.NET中的錯誤404。 查看不顯示

[英]Error 404 in mvc asp.net. View not display

我在創建視圖及其自己的動作結果時遇到麻煩。 我得到的錯誤是這個

錯誤的服務器錯誤'/'。

沒有安全提示。

描述:HTTP404。在總線上運行時,必須在haber quitado,haber cambiado de nombre或任何estar不負責任的時態下進行。 修訂URL siguiente yasegúresede queestáescrita Correctamente。

DirecciónURL solicitada:/ Cursos / AgregarAlumno / 2

這是我的觀點(我知道它尚未完成,但我認為那不是問題)

@model LibreriaEntidad.Cursos
@{
    ViewBag.Title = "AgregarAlumnos";
}

<h2>AgregarAlumnos</h2>

@using (Html.BeginForm())
{
    <fieldset>
        <legend>Cursos</legend>

        @*<div class="editor-label">
            @Html.LabelFor(model => model.idCurso)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.idCurso)
            @Html.ValidationMessageFor(model => model.idCurso)
        </div>*@

        <div class="editor-label">
            @Html.LabelFor(model => model.Nombre)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Nombre)
            @Html.ValidationMessageFor(model => model.Nombre)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.idReparticion)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.idReparticion)
            @Html.ValidationMessageFor(model => model.idReparticion)
        </div>

        @*<div class="editor-label">
            @Html.LabelFor(model => model.Presencual)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Presencual)
            @Html.ValidationMessageFor(model => model.Presencual)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Virtual)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Virtual)
            @Html.ValidationMessageFor(model => model.Virtual)
        </div>*@

            <div class="editor-field">
                @Html.DropDownList("idUsuario", ViewBag.Usuarios as SelectList)
            </div>
            <p>
                <input type="submit" value="Save" />
            </p>
</fieldset>

和我的控制器動作在這里。

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AgregarAlumnos(int id = 0)
{
    Cursos cursos = db.Cursos.Find(id);
    ViewBag.Usuarios = new SelectList(db.Usuario, "idUsuario", "Nombre");
    return View(cursos);
}

提前致謝

您應該從操作中刪除[HttpPost]屬性。

更新:

要顯示視圖,該操作必須接受GET請求。 您應該使用兩種不同的操作來顯示視圖和提交表單。

您需要一個相應的HttpGet方法,因為您當前的方法僅接受HttpPost請求。 添加以下內容:

[HttpPost]
public ActionResult AgregarAlumnos(int id = 0)
{
    Cursos cursos = db.Cursos.Find(id);
    ViewBag.Usuarios = new SelectList(db.Usuario, "idUsuario", "Nombre");
    return View(cursos);
}

HttpGet:-每當任何View首次加載時, HttpGet執行HttpGet方法。 這意味着在首次請求Asp.Net MVC HttpGet方法中的任何URL時,將執行。 這意味着如果有任何URL通過URL接收輸入,我們可以通過HttpGet方法處理輸入。

HttpPost:-單擊MVC表單中的Submit按鈕后,將執行HttpPost方法。 這意味着我們可以使用HttpPost方法處理表單數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM