User-1209166642 posted
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.