Last post Apr 27, 2020 07:30 AM by Rena Ni
Member
25 Points
61 Posts
Apr 24, 2020 08:38 PM|jimap_1|LINK
I know how to use sql server in razor, just quick example:
@page @using System.Data.SqlClient @using System.Collections.Generic; @using System.Data; @using System.Linq; @using System.Threading.Tasks; @using Microsoft.AspNetCore.Http @using Microsoft.Extensions.Configuration @inject IConfiguration Configuration @{ Layout = null; } @{ var name = string.Empty; var submitset = string.Empty; if (Request.HasFormContentType) { name = Request.Form["name"]; @if (string.IsNullOrEmpty(name)) { name = "%"; } } if (!string.IsNullOrEmpty(name)) { var thisoffset = 0; var connectionString = Configuration.GetConnectionString("DefaultConnection"); using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM pets WHERE petname LIKE @lastname ORDER BY petname OFFSET " + thisoffset + " ROWS FETCH NEXT 5 ROWS ONLY", conn); cmd.Parameters.AddWithValue("@lastname", name + "%"); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var vpetid = @reader["petid"]; <div>@reader["petname"]</div> <div>@String.Format("{0:MM/dd/yyyy }", reader["odate"])</div> int vocheck = 0; var mybool = (reader.GetBoolean(reader.GetOrdinal("ocheck"))); if (mybool == true) { vocheck = 1; } <div>@vocheck</div> <br /> <div><a href="editpet?id=@vpetid">test</a></div> } } } else { <form method="post"> <div>Name: <input name="name" /></div> <div><input type="submit" name="submit" /></div> </form> } }
But my question, using sql server and razor only, how to do image uploads?
Meaning have one page to add data, and post to another a razor page and perform upload and save operation. No "model" code behind.
Just razor only.
Contributor
2720 Points
874 Posts
Apr 27, 2020 07:30 AM|Rena Ni|LINK
Hi jimap_1,
What do you mean for `No "model" code behind.`?
Is this thread same as the thread below?
https://forums.asp.net/t/2166349.aspx
For file upload in razor pages,you could refer to:
https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1
Best Regards,
Rena
Member
25 Points
61 Posts
Upload image or multiple using razor page only, no code behind
Apr 24, 2020 08:38 PM|jimap_1|LINK
I know how to use sql server in razor, just quick example:
But my question, using sql server and razor only, how to do image uploads?
Meaning have one page to add data, and post to another a razor page and perform upload and save operation. No "model" code behind.
Just razor only.
Contributor
2720 Points
874 Posts
Re: Upload image or multiple using razor page only, no code behind
Apr 27, 2020 07:30 AM|Rena Ni|LINK
Hi jimap_1,
What do you mean for `No "model" code behind.`?
Is this thread same as the thread below?
https://forums.asp.net/t/2166349.aspx
For file upload in razor pages,you could refer to:
https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1
Best Regards,
Rena