1

我试图在部分方法中传递这个模型

@Html.Partial("_RefillModal",new Refill()
                                     {
                                         PatientId=Model.Id
                                     })

现在在 _RefillModal 中,我正在尝试通过执行 Model.PatientId 来读取 PatientId。但是,我没有得到价值。

我可以通过这样做获得 ID 的值

@Html.Partial("_RefillModal",new Refill(),new ViewDataDictionary(){{"PatientId",Model.Id}})

这是我在部分视图中尝试做的事情

@Html.Hidden("Refill.PatientId",Model.PatientId)

这是发生的 Html 标记

<input id="PatientId" name="PatientId" type="hidden" value="">

但是,当我在页面上的任何位置执行 @Modal.PatientId 时,我确实得到了值

所以看起来,如果我在表单中放入任何东西,它就会被覆盖。有解决办法吗?

 @using (Html.BeginForm())
        {
//any custom input here gets overriden

}
4

1 回答 1

0

由于您没有发布您的问题,因此很难看出问题出在哪里,Partial View但我会提供一些建议。确保您已将实际声明为ModelRefill_RefillModal.

@model Refill

下一步是确保您实际上在这行代码中传递了一个值:

@Html.Partial("_RefillModal", new Refill()
                                 {
                                     /** Make sure that Model.Id actually 
                                         contains some value. */
                                     PatientId = Model.Id
                                 })
于 2013-02-03T06:14:07.223 回答