why values in my view are empty ?!how to do in my controller that i can save and show my fields in new table and new view ?
There's a lot of issues with the code shown. There's a View with two forms but the target actions are not posted; Index3 and Index5. The action that is posted, Index4, does not have a View. What's very confusing is the code snippets look like MVC but
have ASP.NET Core tag helpers.
This post as well as your others are all related to understanding the basics. IMHO, your best course of action is taking the time to go through the tutorials on this site
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
36 Points
132 Posts
why my view is empty ?
Dec 29, 2018 12:43 PM|aabedeni056|LINK
i have my view:
@model WebApplication1.Models.afishstudio
@{
ViewBag.Title = "تایید مدیریت";
}
<script>
// var afishstudio={
// id:$('@Html.TextBoxFor(Model => Model.id)').val();
// name:$('@Html.TextBoxFor(Model => Model.name)').val(),
//family:$('@Html.TextBoxFor(Model => Model.family)').val(),
//date:$('@Html.TextBoxFor(Model => Model.date)').val(),
//time:$('@Html.TextBoxFor(Model => Model.time)').val() }
// $(document).ready(function () {
// $("submit").click(function () {
// $.ajax({
// type: "post",
// url: '@Url.Action("index2")',
// data: {
// id: $('@Html.TextBoxFor(Model => Model.id)').val();
// name: $('@Html.TextBoxFor(Model => Model.name)').val(),
// family: $('@Html.TextBoxFor(Model => Model.family)').val(),
// date: $('@Html.TextBoxFor(Model => Model.date)').val(),
// time: $('@Html.TextBoxFor(Model => Model.time)').val()
// }
// a
// ) })
</script>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/bootstrap-rtl.min.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="panel panel-primary">
<div style="direction:rtl !important;margin:40px auto;width:70%">
<h2> ورود به صفحه تایید آفیش </h2>
</div>
</div>
<div class="panel panel-body">
<div style="direction:rtl !important;margin:40px auto;width:70%">
@using (Html.BeginForm("index3", "afishstudio", FormMethod.Post, null))
{
@Html.AntiForgeryToken()
@Html.TextBoxFor(Model => Model.id, new { @class = "flat" })
@Html.TextBoxFor(Model => Model.name, new { @class = "flat" })
@Html.TextBoxFor(Model => Model.family, new { @class = "flat" })
@Html.TextBoxFor(Model => Model.date, new { @class = "flat" })
@Html.TextBoxFor(Model => Model.time, new { @class = "flat" })
<input type="submit" id="submit" name="submit" value="click" />
}
@using (Html.BeginForm("index5", "modiran", FormMethod.Post, null))
{
@Html.AntiForgeryToken()
<input type="hidden" value="id" />
<label>name=</label>
<input type="text" name="modiran_name" asp-for="input.modiran_name" />
<label>modirkol</label>
<input type="radio" name="modiran_semat" value="modirkol" asp-for="input.modiran_semat" />
<label>ghaemmagham</label>
<input type="radio" name="modiran_semat" value="ghaemmagham" asp-for="input.modiran_semat" />
<label>modir</label>
<input type="radio" name="modiran_semat" value="modir" asp-for="input.modiran_semat" />
<label>masul</label>
<input type="radio" name="modiran_semat" value="masul" asp-for="input.modiran_semat" />
<button type="submit" value="insert" title="ذخیره"> ذخیره </button>
}
<div class="panel-body">
@Html.ActionLink(" ثبت آفیش ", "../formafish/index4", null, new { @class = "btn btn-success" })
</div>
</div>
<div>
@Html.ActionLink("Back to List", "show")
</div>
</div>
</body>
</html>
============================================
my controller :
public ActionResult index4(string modiran_semat,formafish formafish,FormCollection collection)
{
var model = new formafish();
TempData["name"] = model.name;
TempData["family"] = model.family;
TempData["date"] = model.date;
TempData["time"] = model.time;
TempData["modiran_name"] = model.modiran_name;
TempData["modiran_semat"] = model.modiran_semat;
TryUpdateModel(model, collection);
TryUpdateModel(model, modiran_semat);
if (ModelState.IsValid)
{
db.formafish.Add(model);
db.SaveChanges();
return RedirectToAction("PassValue_Index4", "formafish");
}
return View();
}
public ActionResult PassValue_Index4()
{
// ViewBag.id_formafish = TempData["id_formafish"];
ViewBag.name = TempData["name"];
ViewBag.family = TempData["family"];
ViewBag.date = TempData["date"];
ViewBag.time = TempData["time"];
ViewBag.modiran_name = TempData["modiran_name"];
ViewBag.modiran_name = TempData["modiran_semat"];
return View();
}
=================================
my new view :
<div class="form-horizontal">
<div class="panel panel-body">
<div style="direction:rtl !important;margin:40px auto;width:70%">
<div class="form-group">
نام:
<div class="col-md-10">
@Html.TextBox("name", (string)ViewBag.name, new { @style = "width: 300px;" })
</div>
<div class="form-group">
فامیلی :
<div class="col-md-10">
@Html.TextBox("family", (string)ViewBag.family, new { @style = "width: 300px;" })
</div>
<div class="form-group">
تاریخ :
<div class="col-md-10">
@Html.TextBox("date", (Int32)ViewBag.date, new { @style = "width: 300px;" })
</div>
<div class="form-group">
مدت :
<div class="col-md-10">
@Html.TextBox("time", (Int32)ViewBag.time, new { @style = "width: 300px;" })
</div>
my question is :
why values in my view are empty ?!how to do in my controller that i can save and show my fields in new table and new view ?
thanks
All-Star
52231 Points
23303 Posts
Re: why my view is empty ?
Dec 29, 2018 02:32 PM|mgebhard|LINK
There's a lot of issues with the code shown. There's a View with two forms but the target actions are not posted; Index3 and Index5. The action that is posted, Index4, does not have a View. What's very confusing is the code snippets look like MVC but have ASP.NET Core tag helpers.
This post as well as your others are all related to understanding the basics. IMHO, your best course of action is taking the time to go through the tutorials on this site
https://www.asp.net/learn
Keep in mind this is an MVC forum. If you require ASP.NET Core support, post in the ASP,NET Core forum.
Contributor
3710 Points
1431 Posts
Re: why my view is empty ?
Jan 01, 2019 07:34 AM|Yuki Tao|LINK
Hi aabedeni056,
According to your code,some places are not clear.
You did not show the code of Index3 and Index5 action.
How did you operate?
Do you think it is not necessary to show these codes?
So I guess, are you just click this button?
If so, the controller does not receive the parameters,because @Html.ActionLink did not pass parameters.
If you would like to pass :
But I still recommend that you submit data using a form. What you should want is to submit a lot of data instead of a few.
I think you could add some breakpoints on your code to check your parameters and return values.
And hope that you could follow the MVC tutorial system.
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application
Otherwise, your programming will be very tired.
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.