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?
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.
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)
Do you mean you want to get the specified story and
related information about this story and display them on the view?
I made a simple example, you can refer to it.
This example does not use a database.
The example in this linkuses 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);
}
}
ASP.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. Learn more >
None
0 Points
3 Posts
create feedback
Sep 07, 2020 10:43 AM|wejdan|LINK
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?
All-Star
53721 Points
24048 Posts
Re: create feedback
Sep 07, 2020 11:16 AM|mgebhard|LINK
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
All-Star
48730 Points
18189 Posts
Re: create feedback
Sep 07, 2020 11:25 AM|PatriceSc|LINK
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 :
Contributor
3070 Points
868 Posts
Re: create feedback
Sep 08, 2020 06:36 AM|YihuiSun|LINK
Hi wejdan,
Model
Controller
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
Here is the result.
Best Regards,
YihuiSun