html url 多个参数传递,将多个参数从url传递到html.actionlink

我对MVC很新,当我尝试通过URL传递多个参数时,我正在努力进行路由.

从包含URL的页面: /PersonCAFDetail/Index/3?memberid=4

...我正在尝试将Html.ActionLink设置为指向Create操作,使得id = 3且memberid = 4.

阅读了许多类似的帖子后,似乎以下内容应该有效:

@Html.ActionLink("Create New", "Create", null, new { memberid = "memberid" })

但是,这会导致URL创建如下:

Create New

我有一条路线设置为:

routes.MapRoute(

name: "PersonCAFDetail",

url: "PersonCAFDetail/Create/{id}/{memberid}",

defaults: new { controller = "PersonCAFDetail", action = "Create", id = "@\d+", memberid = @"\d+" }

);

控制器接受两个参数,如下所示:

public ActionResult Create(int id, int memberid)

{

int cafID = id;

int personID = memberid;

ViewBag.detailTypeID = new SelectList(db.tCAFDetailTypes, "detailTypeID", "detailType");

ViewBag.cafID = new SelectList(db.tFamilyCAFs, "cafID", "issues");

ViewBag.personID = new SelectList(db.tPersons, "personID", "forename");

return View();

}

任何帮助赞赏.

-------编辑模型----------

namespace WhatWorks.Models

{

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.ComponentModel.DataAnnotations;

public partial class tPersonCAFDetail

{

[Key, HiddenInput(DisplayValue=false)]

public int cafID { get; set; }

[Key, HiddenInput(DisplayValue = false)]

public int personID { get; set; }

[Key, HiddenInput(DisplayValue = false)]

public int detailTypeID { get; set; }

[Required, DataType(DataType.MultilineText)]

public string notes { get; set; }

public string FullName

{

get

{

return tPerson.forename + " " + tPerson.surname;

}

}

public virtual tCAFDetailType tCAFDetailType { get; set; }

public virtual tFamilyCAF tFamilyCAF { get; set; }

public virtual tPerson tPerson { get; set; }

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值