Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Razor Pages and passing parms?

$
0
0

I want to convert the HTML that was working as a MVC view over to  a Razor page. I need to pass the ID to the OnPost(), but I have not seen any example of how to pass the item.AuthorID directly not on an a-tag similar to what in happening on an ActionLink. 

I guess I could use a controller and a view  in the Razor pages project. But do I have to do this to achieve what I was doing with a MVC view with a controller? 

@page
@model IndexModel
@{
    ViewData["Title"] = "Author Page";
}<h1>Authors</h1><!DOCTYPE html><html><head><meta name="viewport" content="width=device-width" /><title>Authors</title></head><body><form method="post"><a asp-page="/Author/Create">Create</a><br /><br /><table border="1" cellpadding="10"><tr><th>AuthorID</th><th>First Name</th><th>Last Name</th><th colspan="4">Actions</th></tr>
            @foreach (var item in Model.AuthorVM.Authors)
            {<tr><td>@item.AuthorID</td><td>@item.FirstName</td><td>@item.LastName</td><td>
                        @Html.ActionLink("Edit", "Edit", new { id = item.AuthorID })</td><td>
                        @Html.ActionLink("Detail", "Detail", new { id = item.AuthorID })</td><td>
                        @Html.ActionLink("Delete", "Delete", new { id = item.AuthorID },
                            new { onclick = "return confirm('Are you sure you wish to delete this author?');" })</td></tr>
            }</table></form></body></html>


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>