检查发件人是否为@ Html.ActionLink

时间:2012-01-18 09:12:15

标签: c# .net asp.net-mvc

我有这个方法:

void myMethod(object sender, DownloadStringCompletedEventArgs e)
    {...}

我有时会通过@ Html.ActionLink调用它,有时候通过单击表中具有“clickableCell”类的单元格来调用它。 如果它是链接,如何检查发件人是什么?

两种情况下的类型都是WebClient。

1 个答案:

答案 0 :(得分:0)

您可以在调用时传递用户状态对象:

var client = new WebClient();
client.DownloadStringCompleted += myMethod;

// You could pass any object
string state = "foo bar";

client.DownloadStringAsync(new Uri("http://foo.bar.com"), state);

然后:

void myMethod(object sender, DownloadStringCompletedEventArgs e)
{
    // will equal "foo bar"
    string state = e.UserState as string;
    ...
}