我在ASP.NET MVC中有一个控制器方法,如下所示:
public ActionResult GetAlbumPictures(int albumId)
{
var album = AlbumRepo.GetSingle(albumId);
var pictures = album.Pictures;
return View(pictures);
}
Run Code Online (Sandbox Code Playgroud)
此方法的路由如下所示:
routes.MapRoute(null,
"pictures"
new { controller = "Album", action = "GetAlbumPictures" });
Run Code Online (Sandbox Code Playgroud)
用户将使用以下URL获取图片,按照相册ID进行过滤:
GET http://server/pictures?albumid=10
Run Code Online (Sandbox Code Playgroud)
但是,我想将querystring参数更改为album而不是albumid:
GET http://server/pictures?album=10
Run Code Online (Sandbox Code Playgroud)
这意味着需要将控制器方法修改为:
public ActionResult GetPictures(int album)
{
...
}
Run Code Online (Sandbox Code Playgroud)
然而,这是不理想的,因为现在的方法有一个名为参数album,其可以被混淆为Album 对象来代替ID的Album.
我的问题是,是否有任何方法配置ASP.NET MVC,以便在路由中,它将接收一个调用的查询字符串参数album,但然后将其作为albumId参数传递给控制器?
PS我知道我可以在路由表中执行此操作:
routes.MapRoute(null,
"album/{albumId}/pictures",
new { controller = "Album", action = "GetAlbumPictures" });
Run Code Online (Sandbox Code Playgroud)
但由于遗留问题,我必须使其适用于查询字符串方法.
这很简单,但我喜欢这种漂亮的pythonic方式.基本上,给定一个字典,返回仅包含以某个字符串开头的那些键的子字典.
» d = {'Apple': 1, 'Banana': 9, 'Carrot': 6, 'Baboon': 3, 'Duck': 8, 'Baby': 2}
» print slice(d, 'Ba')
{'Banana': 9, 'Baby': 2, 'Baboon': 3}
Run Code Online (Sandbox Code Playgroud)
这对函数来说相当简单:
def slice(sourcedict, string):
newdict = {}
for key in sourcedict.keys():
if key.startswith(string):
newdict[key] = sourcedict[key]
return newdict
Run Code Online (Sandbox Code Playgroud)
但肯定有一个更好,更聪明,更易读的解决方案?发电机可以帮忙吗?(我从来没有足够的机会使用它们).
我正在尝试在iphone中构建一个文字游戏.基本上,用户应该能够使用键盘(简单)向屏幕输入一个单词,应用程序应该能够验证单词并建议其他类似的单词(也许可以搜索字典).
我可以使用iphone上内置的单词字典吗?任何指导,以获得这一点将非常感激.
我正在尝试修复ASP Classic应用程序,当我尝试从Recordset对象创建一个数组时.但是,我不能让它正常工作.
这段代码给了我一条记录(最后一条),但据我所知,它是正确的:
Dim Products
Dim Products_cmd
Dim Products_numRows
Set Products_cmd = Server.CreateObject ("ADODB.Command")
Products_cmd.ActiveConnection = Conn
Products_cmd.CommandText = "SELECT prod_id, prod_description FROM dbo.products ORDER BY prod_description ASC"
Products_cmd.Prepared = true
Set Products = Products_cmd.Execute
Products_numRows = 0
Dim arrProducts()
arrProducts = Products.GetRows()
Run Code Online (Sandbox Code Playgroud)
使用此代码给我一个"下标超出范围:'UBound'
Dim Products
Dim Products_cmd
Dim Products_numRows
Set Products_cmd = Server.CreateObject ("ADODB.Command")
Products_cmd.ActiveConnection = Conn
Products_cmd.CommandText = "SELECT prod_id, prod_description FROM dbo.products ORDER BY prod_description ASC"
Products_cmd.Prepared = true
Set Products = Products_cmd.Execute
Products_numRows = 0
Dim …Run Code Online (Sandbox Code Playgroud) 这是我正在尝试做的一个基本示例:
<div class="container">
<h2>Greetings</h2>
<p>All this content, including the HTML comes from a CMS</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我想从CMS中插入更多内容,就像这样
<div class="container">
<h2>Greetings</h2>
<p>NEW YORK - December 29, 2010 - All this content, including the HTML comes from a CMS</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这个标签不起作用,因为它会把它放在之前
标签...
$('.container p').before('NEW YORK - December 29, 2010');
Run Code Online (Sandbox Code Playgroud)
那我怎么能把它插入标签?我无法用类标记p或在标记内放置标记
标签,因为它正在从CMS中吐出.
我正在尝试使用下面的代码和配置从ASP.Net通过GMail发送电子邮件.不幸的是,它似乎没有工作,它也没有抛出错误信息.服务器日志或邮件IIS邮件文件夹中没有任何内容,我甚至检查了来自地址的垃圾箱,看看邮件是否在那里结束.任何帮助将非常感激.
C#部分
public void SendFeedback()
{
string emailFrom = this.Email.Text;
MailMessage message = new MailMessage();
// here is an important part:
message.From = new MailAddress(emailFrom, "Mailer");
// it's superfluous part here since from address is defined in .config file
// in my example. But since you don't use .config file, you will need it.
message.Subject = "www.gumpshen.com - Website Query";
message.IsBodyHtml = true;
message.Body = string.Format(" Name = {0}, Phone = {1}", Name.Text, Phone.Text);
message.Body += Environment.NewLine;
message.Body += Environment.NewLine; …Run Code Online (Sandbox Code Playgroud) 这是我的问题孩子:
jQuery(document).ready(function() {
var a = jQuery('img[title*="after"]');
a.parents('dl.gallery-item').addClass('after');
a.addClass('after');
var b = jQuery('img[title*="before"]');
b.parents('dl.gallery-item').addClass('before');
b.addClass('before');
//the following gives each image a 'name' attribute based on the caption, collapsed.
jQuery('img').each(function() {
var f = jQuery(this).parents('dl.gallery-item').find('dd').text();
var f = f.replace(/\s/g,'');
jQuery(this).attr('name', f);
});
//the following takes each 'name' attribute, finds the before, and sticks it behind the after
jQuery('img.after').hover(function() {
var imgName = jQuery(this).attr('name');
// alert(imgName);
var afterPosition_L = jQuery(this).offset().left;
var afterPosition_T = jQuery(this).offset().top;
var css_string = '{ top: '+ afterPosition_T +'; …Run Code Online (Sandbox Code Playgroud) 这源于今天早些时候关于bignum库和gcc特定的C语言攻击主题的问题.具体来说,使用了这两个声明:
typedef unsigned int dword_t __attribute__((mode(DI)));
Run Code Online (Sandbox Code Playgroud)
在32位系统和
typedef unsigned int dword_t __attribute__((mode(TI)));
Run Code Online (Sandbox Code Playgroud)
在64位系统上.
我假设这是对C语言的扩展,没有办法实现它在当前(C99)标准中实现的任何目标.
所以我的问题很简单:这个假设是否正确?这些陈述对底层内存有何影响?我认为结果是我2*sizeof(uint32_t)对于dword32位系统和2*sizeof(uint64_t)64位系统,我是否正确?
我经常遇到这个术语,即使在谷歌搜索之后,仍然无法理解它究竟意味着什么.是否有一些易于理解(理想情况下有例子)定义了某人可以提供的异步事件?
谢谢!
我最近注意到,Visual Studio 2010调试器不断跳转到使用该[DebuggerStepThrough]属性标记的此方法.

callstack看起来像这样:
[DebuggerStepThrough].我刚刚用foreach循环替换了Linq调用,如下所示,无济于事:

这有点令人烦恼,因为这种方法被频繁调用,我不明白为什么要忽略该属性.
jquery ×2
ado ×1
asp-classic ×1
asp.net ×1
asp.net-mvc ×1
asynchronous ×1
attributes ×1
bignum ×1
c ×1
c# ×1
c99 ×1
debugging ×1
definition ×1
dictionary ×1
email ×1
events ×1
gmail ×1
iis ×1
insert ×1
iphone ×1
ironpython ×1
javascript ×1
jquery-lint ×1
objective-c ×1
python ×1
query-string ×1
routing ×1
selector ×1
slice ×1
smtp ×1
terminology ×1
vbscript ×1
wordpress ×1