简体   繁体   English

从同一视图内的不同控制器调用方法

[英]Call methods from different controllers inside same view

I would need to post a model from a view to two different actions, not in the same controller. 我需要将模型从视图发布到两个不同的操作,而不是在同一个控制器中。

I've tried with ActionLink but I lose data, being the model comples, for example one of the properties is 我已尝试使用ActionLink,但我丢失了数据,作为模型comples,例如其中一个属性是

public IEnumerable<Lot> Lots { get; set; }

The other option I've tried is what is explained here for example 我试过的另一个选项是这里解释的例子

Handling 2 buttons submit Actions in a single View/Form - ASP.NET MVC 2 RTM 处理2个按钮在单个视图/表单中提交操作 - ASP.NET MVC 2 RTM

But I face the problem of having the actions in two different controllers. 但我面临的问题是在两个不同的控制器中进行操作。

I think I can do it with an ajax post, but I've read that is not recommended at all, so I'd love to hear any other option I can't think of. 我想我可以用ajax帖子来做,但我读过根本不推荐,所以我很想听到任何其他我想不到的选择。

Thanks 谢谢

I would need to post a model from a view to two different actions, not in the same controller. 我需要将模型从视图发布到两个不同的操作,而不是在同一个控制器中。

Probably I don't understand what you're looking for, but here's a View that posts to actions in two controllers: 可能我不明白你在寻找什么,但这里是一个发布到两个控制器中的动作的视图:

@using (Html.BeginForm("Action1", "Controller1"))
{
    ...
    <input type="submit" ... />
}
@using (Html.BeginForm("Action2", "Controller2"))
{
    ...
    <input type="submit" ... />
}

This looks too simple to be what you want, so can you elaborate? 这看起来太简单了你想要的,你能详细说明吗?

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

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