0
我是一名MVC新人。我想傳遞參數adminNo,但它始終爲空。過去幾天我一直困在這個問題上。MVC通過參數
控制器
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;
}
定義也許是錯字。 'adminno' vs'adminNo' –
我將其更改爲adminNo。它仍然是空的。 – user3807187
'Model.adminNo'是否爲非空值? – Shyju