我有一个动作方法,显示我的应用程序中的最新5条记录: -
[HttpGet]
public IEnumerable<Technology> LatestAssets()
{
var tech = repository
.LatestTechnology()
.OrderByDescending(a => a.TechnologyID).ToList() ;
return tech;
}
Run Code Online (Sandbox Code Playgroud)
但是如何在呈现_layout视图时调用此操作方法(无需单击任何链接),并迭代显示有关最新5条记录的信息?我的_layout视图有以下部分显示其下的最新记录信息: -
<li class = "nav-header hidden-tablet"
style = "background-color:#3E9BD4 ; color:white">Latest Assets
</li>
Run Code Online (Sandbox Code Playgroud) 我有以下网址,
www.example.com/index.php?r=recommend/create&id=184?
title=Ruins%20of%20Mahabalipuram
&url=http://localhost/index.php/mediadetail/index/184
Run Code Online (Sandbox Code Playgroud)
我需要获取标题和url,它们是查询字符串参数.
有没有人在Yii中获取查询字符串中的值?
让我们想象一下,我有以下行动
public ViewResult Products(string color)
{...}
Run Code Online (Sandbox Code Playgroud)
和url"products"映射到此操作的路由.
根据SEO提示链接/products?color=red
应该返回
200好的
但链接 /products?someOtherParametr=someValue
404未找到
所以问题是 - 如何处理未出现的查询参数并在这种情况下返回404
我在MVC3视图中添加了IF条件,但它不起作用:
@model IEnumerable<StudentRegistrationPortal.Models.CourseRegisterModel>
@{
ViewBag.Title = "Welcome Student";
}
<h2>Welcome
@Context.User.Identity.Name
</h2>
@Html.ActionLink("[Sign Out]", "SignOut", "Student")
<ul>
<li>@Html.ActionLink("Register Courses", "registerCourses", "Course")</li>
</ul>
<h3>Pending Courses</h3>
<table border="1">
<tr>
<th>RollNumber
</th>
<th>Course Code
</th>
<th>Course Name
</th>
<th>Status</th>
</tr>
@foreach (StudentRegistrationPortal.Models.CourseRegisterModel modelValue in Model)
{
if (!string.IsNullOrEmpty(modelValue.Course.Code))
{
<tr>
<td>
@Context.User.Identity.Name
</td>
<td>
@Html.DisplayFor(modelItem => modelValue.Course.Code)
</td>
<td>
@Html.DisplayFor(modelItem => modelValue.Course.Name)
</td>
<td>Pending
</td>
</tr>
}
}
</table>
Run Code Online (Sandbox Code Playgroud)
它在执行IF语句时出现以下错误:
Object reference not set to an instance of an object.
IF条件的目的是确认该modelValue.Course.Code
值不是空字符串或null.
我的代码是测试我试图弄清楚为什么p & ~(p & (p - 1))
不测试2的指数.无论如何,解释器in = 1
因为某种原因不喜欢while循环之前.
码:
def getnumber(str):
num=0
for i in str:
zz = ord(i)-48
if zz<0 or zz>9:
num=-1
break
else:
num=(num*10)+zz
return num
def testexp2(p):
table = {1:1,2:2,4:3,8:4,16:5,32:6,64:7,128:8,256:9}
if p & ~(p & (p - 1)):
print "yes"
else:
print "no"
in = 1
while in is not -1:
in = raw_input("> ")
in = getnumber(in)
if in>-1:
testexp2(in)
else:
print "\nDone\n\n"
Run Code Online (Sandbox Code Playgroud) 我有如下枚举
enum status
{
Active = 1
InAvtive = 2
}
Run Code Online (Sandbox Code Playgroud)
我将 ID 保存在数据库中,就像枚举一样。下面是我的代码。
string str = "";
if (Enum.IsDefined(typeof(Status), StatusID))
str = ((Status)StatusID).ToString();
else
str = "Invalid Value";
Run Code Online (Sandbox Code Playgroud)
我想获取我的 ID 的值。但不工作
编辑:上面的建议不是这个问题的答案.请参阅tymeJV的回答.
我的表单上有一个优惠代码字段,但一旦申请,我希望它停止.目前,您可以继续输入优惠代码,并将不断折扣价格.
我怎么能阻止这种情况发生?
$("#offerapply").click(function () {
if ($("input[name='offercode']").val().toLowerCase() == "discount10") {
price = (price / 10) * 9;
$("#offermsg").text('Thank you. Your 10% discount has been applied.');
}
else {
$("#offermsg").text('Sorry, that Offer Code was not recognised.');
}
calculate();
Run Code Online (Sandbox Code Playgroud) 我有一个在类中声明的1000个const变量的列表.我在保存记录时存储id,在检索时,我必须显示文本.例
public const uint ZenitStPetersburg = 100769;
Run Code Online (Sandbox Code Playgroud)
因此,在检索时,我必须展示ZenitStPetersburg
现在,我正在做切换案例,是否有任何优雅的解决方案来检索文本?
我开始使用libGDX,我想在我的游戏中使用AdMob.
如果有人已经参与其中,请给我一些方法让这件事在游戏中发生?