Ich habe EDITSTORIES Teilansicht, die Daten zu UpdateStories Aktion in Stories Controller, aber es nicht veröffentlichen muss. Es trifft nicht einmal den Haltepunkt.Warum ruft meine Schaltfläche keine Aktion im Controller auf?
@using (Html.BeginForm("UpdateStories", "Stories", FormMethod.Post, new{enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Stories</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.Image, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Image, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Image, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Story, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Story, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Story, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Update" class="btn btn-default" />
</div>
</div>
</div>
}
Aktion:
[HttpPost]
public ActionResult UpdateStories(Stories st)
{
ViewBag.Grid= bo.GetAllImages();
if (bo.UpdateImages(st))
{
ViewBag.Data = "Updated successfully";
}
else
{
ViewBag.Data = "Update failed";
}
ViewBag.Style = "display:none";
return View("GetStories", st);
}
}
Es ist in den GetStories, die die Hauptansicht ist. Es war ein langer Tag und immer noch, es wurde nicht gemacht. Bitte hilf mir dabei.
Update:
Routen:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Stories", action = "AddStories", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "ShowStories",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Stories", action = "ShowStories", id = UrlParameter.Optional }
);
Update:
Ausblick: GetStories
@model HimHer.Models.Stories
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (@Html.BeginForm("GetStories", "Stories", FormMethod.Get))
{
@Html.AntiForgeryToken()
<div style="@ViewBag.Style">
@{
Html.RenderPartial("EditStories", Model);
}
</div>
<hr />
var listData = (List<HimHer.Models.Stories>)ViewBag.Grid;
WebGrid wgImages = new WebGrid(listData, rowsPerPage: 20);
@wgImages.GetHtml(tableStyle: "table table-condensed table-bordered table-striped table-responsive",
columns: wgImages.Columns(
wgImages.Column
(columnName: "Image", header: "Image"),
wgImages.Column
(columnName: "Story", header: "Story"),
wgImages.Column
(columnName: "Image", header: "Download", format: (testItem) => Html.ActionLink("Download", "DownloadStories", new { filename = testItem.Image })),
wgImages.Column
(header: "Edit", format: (testitem) => Html.ActionLink("Edit", "EditStories", new { ID = testitem.ID, Story = testitem.Story, Image = testitem.Image, HiddenID = 1 }))
)
);
}
<h2>Index</h2>
Was ist der Statuscode für das Formular Post-Antwort? – Jasen
Sie haben Ihre Routen in der Frage nicht angezeigt. Oder der Name des Controllers. – mason
@mason udpated und contoller ist Geschichten –