如何从剃刀页面传递一个值?

时间:2017-11-17 07:58:15

标签: c# asp.net-mvc razor

如何将razor中的值传递给C#类?

我想将KeyPath中的值传递给autoCreateSoldPart,但我不知道该怎么做。

剃刀

soldPartSetting

剃刀控制器

<p>
    @Html.Label("Auto recreate sold part", new { @for= "autoCreateSoldPart" })
    @{
        var lstSelect = new List<SelectListItem>()
        {
            new SelectListItem() { Text = "Yes", Value = "true" },
            new SelectListItem() { Text = "No", Value = "false" }
        };

        lstSelect.ForEach(o =>
        {
            if (o.Value == System.Configuration.ConfigurationManager.AppSettings["ReCreateSoldPart"])
            {
                o.Selected = true;
            }
        });

        }
        @Html.DropDownList("autoCreateSoldPart", lstSelect, new { @class = "form-control" })
</p>

C#

    public class HomeController : Controller
    {
        public ActionResult Settings()
        {
            ViewBag.Message = return View();
        }
    }

0 个答案:

没有答案