标签: asp.net-mvc-2

Global.asax 中的 ASP.NET MVC 会话超时处理

如何将程序流重定向到控制器操作。我想模拟 Global.asax.cs 内的 MVC\xe2\x80\x99s RedirectToAction(\xe2\x80\x9cActionName\xe2\x80\x9d, \xe2\x80\x9cControllerName\xe2\x80\x9d, 路由值) 调用。我该怎么做?

\n

asp.net-mvc asp.net-mvc-2

1
推荐指数
1
解决办法
3885
查看次数

不能隐式转换类型'double?' '加倍'

我正在使用asp.net MVC2,我在下面的代码行中遇到错误

<% double RunningTotal = 0; %>
<%foreach (var item in Model)
       {%>
      <%var allowedHours = item.tblPerson.tblPersonAllowedHours.Where(x=>x.Semester == item.Semester).Sum(x=>x.AllowedHoursPerWeek);  %>         
            <tr>
                <td><%: item.Semester %></td>
                <td><%: allowedHours.ToString() %></td>
                <td><%: item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek+x.UL+x.UT) %></td>
                <td><%: item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek+x.UL+x.UT) - allowedHours %></td>
                <%: RunningTotal += (item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek + x.UL + x.UT) - allowedHours) %>

                <td></td>
Run Code Online (Sandbox Code Playgroud)

我得到的错误是在这一行

<%: RunningTotal += (item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek + x.UL + …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-2

1
推荐指数
1
解决办法
9548
查看次数

IE 10登录问题

在win 7和win 8中,我的登录仅停止在IE 10中工作.其余的浏览器表现正常.赢得7的IE 9也正常工作.

这就是我们在网站的mvc部分所拥有的.ajax确认返回到页面,然后重定向到仪表板页面.由于仪表板页面位于登录后面,因此用户将被重定向回登录页面.

public void SignInUser(UserInfo user)
        {
            FormsAuthentication.SignOut();
            SessionService.AbandonSession();
            FormsAuthentication.SetAuthCookie(user.UserId, false);
            //here we put the user in session
            //here we log hit
        }
Run Code Online (Sandbox Code Playgroud)

这就是我们在Kentico CMS方面的经典asp.net.这是一个Web服务请求,执行登录代码,然后确认返回到页面,该页面又重定向到仪表板页面.这里也发生了同样的事情.用户被重定向回登录页面.

FormsAuthentication.SignOut();
                    FormsAuthentication.SetAuthCookie(user.UserId, false);
Run Code Online (Sandbox Code Playgroud)

有没有人在他们的网站上看到过这样的行为?

asp.net authentication asp.net-mvc-2 internet-explorer-10

1
推荐指数
1
解决办法
6914
查看次数

json TimeSpan返回对象

我使用Asp.net MVC4(C#),我想从控制器加载数据来查看.从控制器中返回一个对象,该对象具有TimeSpan类型的属性(HH:DD:MM)这是我的函数:

public JsonResult Buscar(string id){
        string Mensaje = "";
        Models.cSinDenuncias oDenuncia = new Models.cSinDenuncias();
        oDenuncia.sd_iddenuncia = id;
        var denuncia = Servicio.RecuperaDenuncia<Models.cSinDenuncias>(ref Mensaje, oDenuncia.getPk(), oDenuncia);
        return Json(denuncia);
    }
Run Code Online (Sandbox Code Playgroud)

denuncia.sd_horadenuncia例如有这个值18:03:53但是当我在视图中显示这是值[OBJECT OBJECT]时,我无法加载此值在视图中(Html.TextBoxFor):

$('#HoraDen').val(data.sd_horadenuncia);
Run Code Online (Sandbox Code Playgroud)

我如何才能恢复正确的价值?(HH:MM:SS)而不是[OBJECT OBJECT]

问候里卡多

asp.net-mvc json asp.net-mvc-3 asp.net-mvc-2 asp.net-mvc-4

1
推荐指数
1
解决办法
1705
查看次数

为jquery选择器选择标签

<%: Html.CompleteEditorFor(m => m.PetSitterRestrictionPermission.OffLimitAreas)%>
Run Code Online (Sandbox Code Playgroud)

以上生成的代码如下

<label for="PetSitterRestrictionPermission_OffLimitAreas">Off-limit areas</label>
<input id="PetSitterRestrictionPermission_OffLimitAreas" class="text-box single-line" type="text" value="area" name="PetSitterRestrictionPermission.OffLimitAreas" style="display: none;">
<span id="PetSitterRestrictionPermission_OffLimitAreas_validationMessage" class="field-validation-message"></span>
Run Code Online (Sandbox Code Playgroud)

如何label从上面的代码中选择以获得一些jquery效果(作为选择器)?

css jquery asp.net-mvc-2

1
推荐指数
1
解决办法
8177
查看次数

无法将类型为'System.Linq.GroupedEnumerable'的对象强制转换为'System.Collections.Generic.List

我有一个这样的课.

 public static SkillViewModel GetAllList(string ID)
{
    ListViewModel viewModel = new ListViewModel();
    DataTable dt = DAL.GetAllList(ID);

    List<Skill> skills = new List<Skill>();
    foreach (DataRow row in dt.Rows)
    {
        Skill skill = new Skill() { GroupName = row["GroupName"] != null ? row["GroupName"].ToString() : string.Empty, SubName = row["SubName"] != null ? row["SubName"].ToString() : string.Empty};
        skills.Add(skill);
    }
    viewModel.skills = skills;
    viewModel.skills = skills.GroupBy(x => x.GroupName);  //Showing error in this line
   return viewModel;

}
Run Code Online (Sandbox Code Playgroud)

另一个像这样:

 public class SkillViewModel
  {
    public List<Skill> skills { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# casting asp.net-mvc-2

1
推荐指数
1
解决办法
8567
查看次数

输入无效的ID后应返回什么HTTP状态代码?

请求删除不存在的对象时应返回什么状态码?

public ContentResult DeleteEntity(int id, FormCollection FormData)
{
    Database db = new Database();
    TargetEntity te = db.TargetEntities.SingleOrDefault(t => t.Id == id);
    if(te == null)
    {
        Reponse.StatusCode = 400; //Is this correct?
        return Content("Deletion failed. Invalid ID: " + id);
    }
    //Delete the entity
    return Content("Successfully Deleted");
}
Run Code Online (Sandbox Code Playgroud)

该请求本身很好,只是发生了指定的ID无效(或该项目已被删除)的情况,因此我不确定400的范围。我敢肯定,这500个代码甚至不适合此代码,因为服务器上没有出错(只是要求删除不存在的内容)。

哪种状态码在这里最合适?

http http-error http-headers asp.net-mvc-2

1
推荐指数
1
解决办法
1327
查看次数

我如何在.NET中使用Request.RequestUri.Query?(错误11'System.Web.HttpRequestBase'不包含'RequestUri'的定义)

我正在重写一个简单的API GET函数.我想让它更灵活,所以我试着复制这个问题中给出的例子.

我的代码:

  public IEnumerable<Distributeur> GetDistributeurs()
{
    NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
    var departementCode = nvc["departementCode"];
    // BL comes here



    var repository = new LeadRepository();
    return repository.getDistributeurs(departementCode);
}
Run Code Online (Sandbox Code Playgroud)

不幸的是我收到错误'无法解决RequestUri'和构建:

错误11'System.Web.HttpRequestBase'不包含'RequestUri'的定义,并且没有可以找到接受类型'System.Web.HttpRequestBase'的第一个参数的扩展方法'RequestUri'(你是否缺少using指令或者装配参考?)

我去了微软文档,但它们几乎是空的.

.net c# api get asp.net-mvc-2

1
推荐指数
1
解决办法
7918
查看次数

MVC CORE 2.0.0在每个页面上运行c#代码

每次查看基于_layout.cshtml的任何页面时,我都需要运行一些c#代码.我不想在每个controller.cs文件中添加一些东西,就像你曾经在ASP.NET的MasterPage.cs中使用的一样.

无法得到这个

在MVC,C#中的每个请求中运行一个方法?

或这个

Asp.Net Core中的@ Html.Action

运行,不知道是不是因为它们不是CORE 2.0.0,我只是遇到了很多编译错误.我想做的就是能够运行这样的代码

public class myClass {
    public static bool returnTrue() {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

每次加载每个页面.

asp.net-mvc-2 asp.net-core-mvc

1
推荐指数
1
解决办法
948
查看次数

路由MVC问题

我看了很多帖子,我也没看到我的故事.

有人可以帮我一下吗.

有我的global.asax

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                
           routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
           routes.MapRoute("UserName", "Account/{action}/{username}",
          new { action = "EditProfile", controller = "Account" });   

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
Run Code Online (Sandbox Code Playgroud)

当我使用

<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %>
Run Code Online (Sandbox Code Playgroud)

我有这个网址

HTTP://本地主机:8458 /帐号/ EditProfile用户名= cboivin

如果我尝试直接调用URL如 http:// localhost:8458/Account/EditProfile/cboivin

不工作......

我的AccountController中有我的方法

 public ActionResult EditProfile(string …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-2

0
推荐指数
1
解决办法
100
查看次数