[英]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.