我是MVC的新人。我想传递参数adminNo,但它总是为空。过去几天我一直坚持这个问题。
控制器
public ActionResult PledgeForm(string adminNo)
{
var result = new StudentJournalQuery().GetStudentInfo(adminNo);
return View(result);
}
RouteConfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default1",
url: "{controller}/{action}/{adminno}",
defaults: new { controller = "Home", action = "Index", adminno = UrlParameter.Optional }
);
ActionMethod
<a href="@Url.Action("PledgeForm", "ManageSipStudentJournal", new {adminNo = @Model.adminNo, area= string.Empty})">View Pledge Form</a>
SQL查询以下是SQL查询
public StudentJournalSummary GetJournalSummary(string adminNo)
{
var StudentJournalSummary = new StudentJournalSummary();
const string _CountSql =
@"select count(sjd.WeekNo) TotalWeek, sum(sj.TotalDaysRecord) TotalDaysRecord, count(case sjd.JournalStatusCode when 'D' then 1 else null end) PendingComplete from StudentJournalDate sjd left outer join
(select sj.WeekNo,
case when RTRIM(sj.Day1Journal) = '' or sj.Day1Journal is null then 0 else 1 end +
case when RTRIM(sj.Day2Journal) = '' or sj.Day2Journal is null then 0 else 1 end +
case when RTRIM(sj.Day3Journal) = '' or sj.Day3Journal is null then 0 else 1 end +
case when RTRIM(sj.Day4Journal) = '' or sj.Day4Journal is null then 0 else 1 end +
case when RTRIM(sj.Day5Journal) = '' or sj.Day5Journal is null then 0 else 1 end +
case when RTRIM(sj.Day6Journal) = '' or sj.Day6Journal is null then 0 else 1 end +
case when RTRIM(sj.Day7Journal) = '' or sj.Day7Journal is null then 0 else 1 end as TotalDaysRecord
from StudentJournal sj ) as sj on sjd.WeekNo = sj.WeekNo";
using (var connection = Db.SqlServer())
{
StudentJournalSummary = connection
.Query<StudentJournalSummary>(_CountSql, new { adminNo }).FirstOrDefault();
}
return StudentJournalSummary;
}
答案 0 :(得分:0)
你忘记在Model.adminNo中删除@它不需要已经在@ Url.Action中定义了
<a href="@Url.Action("PledgeForm", "ManageSipStudentJournal", new {adminNo = Model.adminNo, area= string.Empty})">View Pledge Form</a>