razor类库的页面代码
提交的时候如果想提交到后台某个方法,
那么必须 method=“post” 然后提交按钮上必须增加
asp-page-handler=“Save” Save 可以自己取名
@page
@model WSI.Component.FanYiSwitch_Pages.ConfigPageModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 必须有这个才能正确提交
@{
ViewData["Title"] = "翻译组件配置";
Layout = "~/Pages/Shared/_Layout.cshtml";
}
<form method="post">
<select name="FeeItem">
<option value="1">翻译</option>
<option value="0">不翻译</option>
</select>
<br />
<button type="submit" asp-page-handler="Save">提交</button>
</form>
那么会对应提交到后台代码OnPostSave中执行.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using WSI.DB;
using Dapper;
namespace WSI.Component.FanYiSwitch_Pages
{
public class ConfigPageModel : PageModel
{
public ConfigPageModel(DBConnections DBConnections)
{
this.DB = DBConnections;
}
public DBConnections DB { get; set; }
public void OnGet()
{
}
public void OnPostSave(
int Sex,
int PatientType,
int FeeStatus,
int Age,
int PatientDepartment,
int SampleCharacter,
int SampleType,
int Emergency,
int FeeItem
)
{
this.DB.WSIDBConnection.Execute("update ws_translate_switch set value=@value where SwitchName='Sex' ",new { value=Sex });
this.DB.WSIDBConnection.Execute("update ws_translate_switch set value=@value where SwitchName='PatientType' ", new { value = PatientType });
this.DB.WSIDBConnection.Execute("update ws_translate_switch set value=@value where SwitchName='FeeStatus ' ", new { value = FeeStatus });
}
}
}
注意 在razor类库项目中的cshtml
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
是必须的