简体   繁体   English

如何从视图中调用 controller

[英]How to call a controller from a view

Im using MVC and Im having the following html code to get data from mssql.我使用 MVC 并且我有以下 html 代码从 mssql 获取数据。

In the following code it calls the DebitAndCreditNotesService and the function GetCheckoutRoomInfo在以下代码中,它调用 DebitAndCreditNotesService 和 function GetCheckoutRoomInfo

@Html.Partial("_InHouse", new DebitAndCreditNotesService().GetCheckoutRoomInfo())

But how can i modify the above code to call a controller and function it got.但是我如何修改上面的代码来调用它得到的 controller 和 function。 Suppose i got a controller and method for eg- CreditNoteController and the method is Inhouse假设我有一个 controller 和例如 CreditNoteController 的方法,方法是 Inhouse

public class CreditNotesController : BaseController
{
public PartialViewResult InHouse()
        {

        }
}

How can i do this?我怎样才能做到这一点? Im still a beginner我还是个初学者

I don't know your model structure, but;我不知道你的 model 结构,但是;

public PartialViewResult InHouse()
{
CheckoutRoom model = new CheckoutRoom();
return View(model);
}

you can do it with a similar code.你可以用类似的代码来做到这一点。

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

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