I want to display partial html
after POST
on my Form
.
First, i have Index.cshtml
file:
@model Models.IndexViewModel
@{
ViewBag.Title = "Home Page";
var taskList = ViewBag.TaskList;
}
@section styles {
<link rel="Stylesheet" href="@Href("~/Content/Index.css")" />
}
<div class="row">
<div class="col-md-12">
<section id="sendedTaskForm">
@using (Html.BeginForm("FromInput", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
<div class="form-group">
@Html.LabelFor(m => m.Code, new { @class = "col-md2 control-label" })
<div class="col-md-12">
@Html.TextAreaFor(m => m.Code, new { @class = "form-control", @cols = 100, @rows = 20 })
@Html.ValidationMessageFor(m => m.Code)
</div>
</div>
<div class="form-group">
@Html.LabelFor(x => x.TaskId)
<div class="col-md-12">
@Html.DropDownListFor(x => x.TaskId, Model.Tasks)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Submit" />
</div>
</div>
}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Login " onclick="@("window.location.href='" + @Url.Action("Login", "Home") + "'");" />
</div>
</div>
</section>
</div>
</div>
@section Scripts {
@Scripts.Render("~/Scripts/jquery.validate.min.js")
@Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js")
}
After clicking Submit
button, form is passed to my method in HomeController.cs
that for today's state its looking like this:
//i return Index.cshtml like that:
public ActionResult Index()
{
var model = new IndexViewModel { Tasks = new List<SelectListItem>() };
foreach (Models.Task task in this.db.Tasks)
{
model.Tasks.Add(new SelectListItem { Value = task.Id.ToString(), Text = task.Name });
}
return this.View(model);
}
//i recive form from Index.cshtml here
[ValidateInput(false)]
[HttpPost]
public ActionResult FromInput(IndexViewModel model)
{
var result = new MethodViewModel() //app logic, look at another view models in Index and Method
return this.View("Succes", model: result);
}
My question is, how to return Succes.cshtml
from my FromInput
method to Index.cshtml
as partial view? I want to see output from FromInput
method not as another Succes.cshtml
but as part of Index.cshtml
(thats why i mentioned Partial Html
, maybe it will work but i dont know how) What i need to do first? What changes i need to make to make it simple?
EDIT:
Im trying some options:
To my Index.cshtml
i added div
on below of html document
and another button :
<div id="output">
</div>
<button id="submit">submit</button>
And to Index.cshtml
i added script
:
<script>
document.getElementById("submit").onclick = function () { myFunction() };
function myFunction() {
$.get('@Url.Action("FromInput", "Home")', function(data) {
$('#output').replaceWith(data);
});
}
But it not work