简体   繁体   English

父视图内的部分视图不向控制器发送数据 - asp.net MVC

[英]Partial view inside parent view not sending data to controller - asp.net MVC

I have a partial view name test/index 我有一个部分视图名称测试/索引

following is the code - 以下是代码 -

@model MyFirstMVC.Models.testModels
@using (Html.BeginForm())
{ 
     @Html.TextBox("test1")
     <input type="submit" value="click" />
     @ViewBag.a
}

And the controller of this partial view is following - 这部分视图的控制器如下 -

    [HttpPost]
    public ActionResult Index(MyFirstMVC.Models.testModels m)
    {
        ViewBag.a = Request["test1"].ToString() + " from controler";
        return View(m);
    }

In my parent view I am embedding my partial view like below - 在我的父视图中,我正在嵌入我的局部视图,如下所示 -

 @Html.Partial("../test/index",new MyFirstMVC.Models.testModels())

When I run the application, the partial view do appear in the parent view. 当我运行应用程序时,部分视图确实出现在父视图中。 But when I enter value inside partial view and submit then nothing is happening (the value is not forwarding to the controller of partial view - I have checked that the controller action method related to the partial view is not invoking either by setting break-point). 但是当我在局部视图中输入值并提交然后没有发生任何事情(该值不转发到局部视图的控制器 - 我已经检查了与局部视图相关的控制器操作方法没有通过设置断点来调用) 。

Any help will be appreciated. 任何帮助将不胜感激。 Why my partial view is not sending value to its controller? 为什么我的局部视图不向其控制器发送值?

You need to specify the controller and action names in Html.BeginForm() if your not posting back to the same method that generated the view 如果您没有回发到生成视图的相同方法,则需要在Html.BeginForm()指定控制器和操作名称

@model MyFirstMVC.Models.testModels
@using (Html.BeginForm("Index", "Test"))
{ 
    @Html.TextBox("test1")
    <input type="submit" value="click" />
    @ViewBag.a
}

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

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