locked
create feedback RRS feed

  • Question

  • User-1952405402 posted

    I have table of stories data and each row they have specific id , if i want create new feedback of one story how can i send the id of story to create page?

    Monday, September 7, 2020 10:43 AM

All replies

  • User475983607 posted

    wejdan

    I have table of stories data and each row they have specific id , if i want create new feedback of one story how can i send the id of story to create page?

    Typically, an Id is submitted the URL using MVC routes.   I think you'll be interested in going through an MVC Getting Started tutorial.  The concept of passing data is covered every beginning level MVC tutorial.

    MVC 5

    https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started

    MVC Core

    https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?view=aspnetcore-3.1&tabs=visual-studio

    Monday, September 7, 2020 11:16 AM
  • User753101303 posted

    Hi,

    See any MVC tutorial such as: 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 :

    • the id is part of the url
    • it is used to fetch and render data (ie you don't "create a page" for each and every value but you have a single page using this id value to fetch data relevant to this particular id from a database)

    Monday, September 7, 2020 11:25 AM
  • User1686398519 posted

    Hi wejdan,

    how can i send the id of story to create page

    1. Do you mean you want to get the specified story and related information about this story and display them on the view?
    2.  I made a simple example, you can refer to it.
      • This example does not use a database.
      • The example in this link uses EF to connect to the database, you can refer to the usage.

    Model

        public class Story
        {
            public int Id { get; set; }
            public string Name{ get; set; }
            public string Datails { get; set; }
            public List<Story> allStory()
            {
                List<Story> testlist = new List<Story>();
                for (int i = 0; i < 10; i++)
                {
                    testlist.Add(new Story {Id=i,Name="Name"+i.ToString(), Datails= "Datails"+i.ToString() });
                    }
                return testlist;
            }
        }

    Controller

        public class StoryController : Controller
        {
            public ActionResult Index()
            {
                Story s = new Story();
                return View(s.allStory());
            }
            [HttpGet]
            public ActionResult Edit(int id)
            {
                Story s = new Story();
                var currentstory=s.allStory().Where(m => m.Id == id).SingleOrDefault();
                return View(currentstory);
            }
        }

    Index

    @model IEnumerable<DailyMVCDemo.Models.Story>
    <h2>Index</h2>
    <table class="table">
        <tr>
            <td>@Html.DisplayNameFor(m => m.Id)</td>
            <td>@Html.DisplayNameFor(m => m.Name)</td>
            <td>@Html.DisplayNameFor(m => m.Datails)</td>
            <td></td>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(m => item.Id)</td>
                <td>@Html.DisplayFor(m => item.Name)</td>
                <td>@Html.DisplayFor(m => item.Datails)</td>
                <td>@Html.ActionLink("Edit", "Edit", "Story", new { id = item.Id },null)</td>
            </tr>
        }
    </table>

    Edit

    @model DailyMVCDemo.Models.Story
    <h2>Edit-@Model.Name</h2>
    <table class="table">
        <tr>
            <td>@Html.DisplayNameFor(m => m.Id)</td>
            <td>@Html.DisplayNameFor(m => m.Name)</td>
            <td>@Html.DisplayNameFor(m => m.Datails)</td>
        </tr>
        <tr>
            <td>@Html.DisplayFor(m => m.Id)</td>
            <td>@Html.DisplayFor(m => m.Name)</td>
            <td>@Html.DisplayFor(m => m.Datails)</td>
        </tr>
    </table>
    @Html.ActionLink("Back to Index", "Index", "Story")

    Here is the result.

    Best Regards,

    YihuiSun

    Tuesday, September 8, 2020 6:36 AM