简体   繁体   English

从MVC控制器解析对象以查看C#

[英]Parse an object from MVC controller to view C#

I am storing an object from a list to a local variable and trying to pass it to a view like below: 我将对象从列表存储到局部变量,然后尝试将其传递给如下所示的视图:

 public class BedController : Controller
{
    // GET: Bed
    public ActionResult Index(PatientRegister model, int id)
    {
        var patient = PatientRegisterController.BedsList.Single(x => x.NewPatient.BedNumber.Equals(id.ToString()));
        return View(patient);
    }
}

But I don't know how to access this object from the view itself something like 但是我不知道如何从视图本身访问该对象,例如

patient.SelectSomeOfTheProperites //This is the object that I parsed from controller 

Add return object type as model 将返回对象类型添加为模型

@model Bed

Access the return object property as 访问返回对象属性为

@model.SelectSomeOfTheProperites

Hope this helps! 希望这可以帮助!

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

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