繁体   English   中英

如何将参数传递给控制器​​的@renderpage调用?

[英]How can I pass parameters to a @renderpage call for the controller?

我有一个视图,使用@renderpage渲染其他4个视图以用于创建/更新。 我的创建页面可以正常工作,但是现在我希望可以根据需要更新数据,但是我无法通过它将数据传递给呈现的页面控制器。 我不能使用局部视图,因为那时我没有模型。 我在Edit Call中得到了那个模型。

我在尝试谷歌搜索时尝试的所有方法。 我使用了一个包含要传递的参数的类进行了尝试,我仅尝试了一个测试ID等。 数据不会显示在控制器中。

RenderPage调用:

   @using (Html.BeginForm("Edit", "Person", FormMethod.Post, new { id = "person" }))
        {
            var id = Request["PersonId"];

            if (id != null)
            {
                PageInfo pageinfo = new PageInfo(Int32.Parse(id));
                @RenderPage("~/Views/Person/Edit.cshtml", pageinfo.PostId)
            }

        }

控制器:

public class PersonController : Controller
    {
        ProjekthafenEntities phentitis = new ProjekthafenEntities();
        // GET: Person
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Person person)
        {
            phentitis.Person.Add(person);
            phentitis.SaveChanges();

            return Json(data: new ResponseData(true, "", "success"));
        }


        public ActionResult Edit(int id)
        {
            return View(phentitis.Person.Find(id));
        }

    }

我希望在Edit函数中获得一个值,但我只会得到null。

谢谢您的帮助!

对于所有感兴趣的人,我解决了这样的问题:

 @using (Html.BeginForm("Edit", "Firma", FormMethod.Post, new { id = "firma" }))
        {
            var id = Int32.Parse(Request["FirmaId"]);
            ProjekthafenEntities phentitis = new ProjekthafenEntities();

            @Html.Partial("~/Views/Firma/Edit.cshtml", phentitis.Firma.Find(id));

        }

并将Controller更改为此:

public ActionResult Edit(Firma firma)
        {  
            return View(firma);
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM