Your redirect to index5 does not pass any data. A redirect is used to tell the browser to load a new url. The only data passed is on the query string (part of the url).
You redirected multiple times with some parameters.
index4 ->index5->PassValue_Index3
Are you sure your parameters have values from index4 to index5?
aabedeni056
return RedirectToAction("index5");
This line can not pass parameters.
public ActionResult index5(string modiran_semat,FormCollection collection)
I suggest you could add some breakpoints and check if the parameters(modiran_semat,collection) have values.
I think you can combine these action to avoid multiple redirects.
Best Regards.
Yuki Tao
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.
with my controller 1: my fields value save in db but dont show in new view that i write . please help me .
Have you ever solved this problem?
As bruce and Yuki Tao said, you didn't transfer data to the Index5 action method. You could modify your code as below, and transfer the modiran to "index5",
code like this:
return RedirectToAction("index5", modiran);
and
public ActionResult index5(modiran modiran)
Besides, in the index5 action method, you could also try to query the database and get the latest data.
Best regards
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
36 Points
131 Posts
why my fields in my view is empty
Dec 25, 2018 10:27 AM|aabedeni056|LINK
hello .
i have view with textbox and radio button . with my controller 1: my fields value save in db but dont show in new view that i write . please help me .
controller 1(save in db) :
public ActionResult index4(string modiran_semat, modiran modiran)
{
TryUpdateModel(modiran, modiran_semat);
if (ModelState.IsValid)
{
db.modiran.Add(modiran);
db.SaveChanges();
return RedirectToAction("index5");
}
return View();
// return RedirectToAction("index3");
}
controller 2 , controller 3:
public ActionResult index5(string modiran_semat,FormCollection collection)
{
// var semat = Request.Form["modiran_semat"];
var model = new modiran();
TryUpdateModel(model, collection);
// TryUpdateModel(model, modiran_semat);
TempData["modiran_id"] = model.modiran_id;
TempData["modiran_name"] = model.modiran_name;
TempData["modiran_semat"] = model.modiran_semat;
return RedirectToAction("PassValue_Index3", "modiran");
}
public ActionResult PassValue_Index3()
{
ViewBag.modiran_id = TempData["modiran_id"];
ViewBag.modiran_name = TempData["modiran_name"];
ViewBag.modiran_semat = TempData["modiran_semat"];
return View();
}
but dont show in my new view :
<div class="form-group">
id:
<div class="col-md-10">
@Html.TextBox("id", (Int32)ViewBag.modiran_id, new { @style = "width: 300px;" })
</div>
</div>
<div class="form-group">
نام :
<div class="col-md-10">
@Html.TextBox("name", (string)ViewBag.modiran_name, new { @style = "width: 300px;" })
</div>
</div>
<div class="form-group">
سمت :
<div class="col-md-10">
@Html.TextBox("semat", (string)ViewBag.modiran_semat, new { @style = "width: 300px;" })
</div>
</div>
please help me
All-Star
57874 Points
15505 Posts
Re: why my fields in my view is empty
Dec 25, 2018 04:39 PM|bruce (sqlwork.com)|LINK
Contributor
3710 Points
1431 Posts
Re: why my fields in my view is empty
Dec 26, 2018 05:25 AM|Yuki Tao|LINK
Hi aabedeni056,
I saw your code,
You redirected multiple times with some parameters.
index4 ->index5->PassValue_Index3
Are you sure your parameters have values from index4 to index5?
This line can not pass parameters.
I suggest you could add some breakpoints and check if the parameters(modiran_semat,collection) have values.
I think you can combine these action to avoid multiple redirects.
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.
All-Star
45489 Points
7008 Posts
Microsoft
Re: why my fields in my view is empty
Jan 01, 2019 07:57 AM|Zhi Lv - MSFT|LINK
Hi aabedeni056,
Have you ever solved this problem?
As bruce and Yuki Tao said, you didn't transfer data to the Index5 action method. You could modify your code as below, and transfer the modiran to "index5",
code like this:
return RedirectToAction("index5", modiran);
and
Besides, in the index5 action method, you could also try to query the database and get the latest data.
Best regards