why my view is empty ? RRS feed

  • Question

  • User1928394251 posted

    i have my view:

    @model WebApplication1.Models.afishstudio

    ViewBag.Title = "تایید مدیریت";

    // 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

    // ) })


    <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>


    <div class="panel panel-primary">
    <div style="direction:rtl !important;margin:40px auto;width:70%">
    <h2> ورود به صفحه تایید آفیش </h2>
    <div class="panel panel-body">

    <div style="direction:rtl !important;margin:40px auto;width:70%">

    @using (Html.BeginForm("index3", "afishstudio", FormMethod.Post, null))


    @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))



    <input type="hidden" value="id" />

    <input type="text" name="modiran_name" asp-for="input.modiran_name" />

    <input type="radio" name="modiran_semat" value="modirkol" asp-for="input.modiran_semat" />

    <input type="radio" name="modiran_semat" value="ghaemmagham" asp-for="input.modiran_semat" />

    <input type="radio" name="modiran_semat" value="modir" asp-for="input.modiran_semat" />

    <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" })



    @Html.ActionLink("Back to List", "show")





    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)
    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 class="form-group">

    فامیلی :

    <div class="col-md-10">

    @Html.TextBox("family", (string)ViewBag.family, new { @style = "width: 300px;" })


    <div class="form-group">

    تاریخ :

    <div class="col-md-10">

    @Html.TextBox("date", (Int32)ViewBag.date, new { @style = "width: 300px;" })


    <div class="form-group">

    مدت :

    <div class="col-md-10">

    @Html.TextBox("time", (Int32)ViewBag.time, new { @style = "width: 300px;" })


    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 ?


    Saturday, December 29, 2018 12:43 PM

All replies

  • User475983607 posted

    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 ?

    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


    Keep in mind this is an MVC forum.  If you require ASP.NET Core support, post in the ASP,NET Core forum.

    Saturday, December 29, 2018 2:32 PM
  • User1520731567 posted

    Hi aabedeni056,

    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 ?

    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?

    @Html.ActionLink(" ثبت آفیش ", "../formafish/index4", null, new { @class = "btn btn-success" })

    If so, the controller does not receive the parameters,because @Html.ActionLink did not pass parameters.

    If you would like to pass :

    " ثبت آفیش ", linkText
    "../Home2/PassValue_Index", actionName
    new { modiran_semat = "111",key2=value2,... }, routeValues
    new { @class = "btn btn-success"} htmlAttributes

    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.


    Otherwise, your programming will be very tired.

    Best Regards.

    Yuki Tao

    Tuesday, January 1, 2019 7:34 AM