相关疑难解决方法(0)

在RedirectToAction中传递对象

我想在RedirectToAction中传递对象.这是我的代码:

RouteValueDictionary dict = new RouteValueDictionary();
            dict.Add("searchJob", searchJob);
            return RedirectToAction("SearchJob", "SearchJob", dict);
Run Code Online (Sandbox Code Playgroud)

其中searchJob是SearchJob的实例.但我没有得到SearchJob动作方法的数据.相反,我得到searchJob = Entity.SearchJob的查询字符串.请帮我.我究竟做错了什么?

c# asp.net asp.net-mvc asp.net-mvc-3

23
推荐指数
2
解决办法
4万
查看次数

通过参数mvc重定向到Action

我想重定向到其他Controller中的一个动作,但它在这里不起作用我的ProductManagerController中的代码:

[HttpPost]
public ActionResult RedirectToImages(int id)
{
    return RedirectToAction("Index","ProductImageManeger", new   { id=id   });
}
Run Code Online (Sandbox Code Playgroud)

这在我的ProductImageManagerController中:

[HttpGet]
public ViewResult Index(int id)
{
    return View("Index",_db.ProductImages.Where(rs=>rs.ProductId == id).ToList());
}
Run Code Online (Sandbox Code Playgroud)

它没有参数很好地重定向到ProductImageManager/Index(没有错误)但是使用上面的代码我得到这个:

参数字典包含"... Controllers.ProductImageManagerController"中方法"System.Web.Mvc.ViewResult Index(Int32)"的非可空类型"System.Int32"的参数"ID"的空条目.可选参数必须是引用类型,可空类型,或者声明为可选参数.参数名称:参数

c# asp.net-mvc redirect asp.net-mvc-5

13
推荐指数
2
解决办法
10万
查看次数

如何在Asp.NET MVC中使用RedirectToAction()传递多个对象?

我想使用redirectToAction()方法传递多个对象.下面是我要重定向到的动作结果.

public ActionResult GetEmployees(Models.Department department, Models.Category category, Models.Role role)
        {  

return View();
}
Run Code Online (Sandbox Code Playgroud)

我想做类似下面的事情

public ActionResult test()
{
Models.Department dep = new Models.Department();
Models.Category cat.......etc

return RedirectToAction("GetEmployees", dep, cat, role); }
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激 - 谢谢

更新

我可以使用类似的东西吗?

 Models.Department dep = new Models.Department() { DepId = employee.DepartmentId };
                    Models.Category cat = new Models.Category() { CatId = employee.JobCategoryId };
                    Models.Role title = new Models.Role() { RoleId = employee.JobTitleId };

            return RedirectToAction("GetEmployees", new { department = dep, category = cat, role = title });
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

7
推荐指数
2
解决办法
2万
查看次数

asp.net core 2 razor pages route with id

There are two page one is Edit page and the other is Main Detail page which is combined data of some entities In edit page : after edit done and I posted the data to API as below

public async Task<IActionResult> OnPostAsync(Guid id)
    {
        ManufacturerAuthorizedPerson.Id = id;
        ManufacturerAuthorizedPerson.ManufacturerId = GetManufacturerId(id);
        if (!ModelState.IsValid)
        {
            await OnGetAsync(id);
            return Page();
        }
        HttpResponseMessage = await httpSystemApi.PutAsync("ManufacturerAuthorizedPersons", ManufacturerAuthorizedPerson);
        if (HttpResponseMessage.IsSuccessStatusCode)
        {
            return RedirectToPage("../Detail", ManufacturerAuthorizedPerson.ManufacturerId);
        }
        else
        {
            await OnGetAsync(id);
            return Page();
        }
    }
Run Code Online (Sandbox Code Playgroud)

The ID …

c# asp.net-core-2.0 razor-pages

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

localhost页面无效.localhost重定向了你太多次了

调试我的MVC程序时遇到问题,我想访问名为"UserActivity"的数据库.在浏览器上,它说"localhost页面不起作用

localhost重定向了你太多次了."

但没有显示具体的错误位置.

这是我的UserActivtyController,GET/UserActivity/Index代码:

public class UserActivityController : BaseController
{
    //GET /UserActivity/Index
    public ActionResult Index(string returnUrl, int page = 1, string sort = "Id", string sortDir = "ASC", string filter = null)
    {
        String query = @"
            SELECT Id
            ,CreatedBy
            ,CreatedOn
            ,ModifiedBy
            ,ModifiedOn
            ,ContactId
            ,EntityName
            ,EntityId
            ,ActivityType
            ,ActivityStatus
            ,DueDate
            ,ActualEndDate
            ,MasqueradeOn
            ,MasqueradeBy 
        FROM UserActivity 
        -- ORDER BY CreatedOn DESC
        -- OFFSET (@PageNumber -1) * 30 ROWS
        -- FETCH NEXT 30 ROWS ONLY
            ";

        //string countQuery = @""

        List<UserActivityModels> userActivity = …
Run Code Online (Sandbox Code Playgroud)

asp.net c#-4.0 asp.net-mvc-4

6
推荐指数
1
解决办法
4万
查看次数

在MVC 3中的url中传递多个参数

我在控制器中有一个名为"Registration"的动作方法

public ActionResult Facility(int id = 0, int contractId = 0)
Run Code Online (Sandbox Code Playgroud)

当我从url调用这个方法时

/Registration/Facility/0?contractId=0
Run Code Online (Sandbox Code Playgroud)

它工作正常.现在,当我尝试在另一种方法中构建上面的url时

return RedirectToAction("Facility/0?contractId="+ model.ContractId);
Run Code Online (Sandbox Code Playgroud)

它不起作用,浏览器中的网址构造不好就像它

/Registration/Facility/0%3fcontractId%3d0
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我,我在这里做错了什么?

asp.net asp.net-mvc-3

5
推荐指数
1
解决办法
2万
查看次数

向RouteValueDictionary添加复杂类型的数组

我想知道是否有一种优雅的方法可以将一组复杂类型添加到RouteValueDictionary或兼容类型?

例如,如果我有一个类和一个动作:

public class TestObject
{
    public string Name { get; set; }
    public int Count { get; set; }

    public TestObject()
    {
    }

    public TestObject(string name, int count)
    {
        this.Name = name;
        this.Count = count;
    }
}

public ActionResult Test(ICollection<TestObjects> t)
{
    return View();
}
Run Code Online (Sandbox Code Playgroud)

然后我知道如果我通过URL"/Test?t[0].Name=One&t[0].Count=1&t[1].Name=Two&t[1].Count=2"调用此动作,MVC将映射那些查询字符串参数自动返回ICollection类型.但是,如果我使用Url.Action()在某处手动创建链接,并且我想传递参数的RouteValueDictionary,当我向RouteValueDictionary添加ICollection时,Url.Action只是将其呈现为类型,如&t = System.Collections.Generic.List.

例如:

RouteValueDictionary routeValDict = new RouteValueDictionary();
List<TestObject> testObjects = new List<TestObject>();

testObjects.Add(new TestObject("One", 1));
testObjects.Add(new TestObject("Two", 2));
routeValDict.Add("t", testObjects);

// Does not properly create the parameters for the List<TestObject> collection.
string …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-4

2
推荐指数
2
解决办法
5348
查看次数

如何从一个动作重定向到另一个动作但在MVC 3中提供它的参数?

我知道你可以从一个动作重定向到另一个动作,如:

public ActionResult Index() {
   return View();
}

public ActionResult OtherAction(){
   return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)

好.我没有找到我的问题的解决方案:如何重定向到具有参数的操作?例如:

public ActionResult Index(string v1, int i1) {
   return View();
}

public ActionResult OtherAction(string value, int size){
   return RedirectToAction("Index", // here need some adjustements or another trick);
}
Run Code Online (Sandbox Code Playgroud)

对不起,但我没有在这里找到任何相关的问题,也许我不知道使用搜索:)

c# asp.net-mvc-3

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