里面的父视图不是将数据发送到控制器的局部视图 - asp.net MVC [英] Partial view inside parent view not sending data to controller - asp.net MVC

查看:81
本文介绍了里面的父视图不是将数据发送到控制器的局部视图 - asp.net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个局部视图名test /指数

I have a partial view name test/index

以下是code -

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).

任何帮助将AP preciated。为什么我的部分观点不发送值到它的控制器?

Any help will be appreciated. Why my partial view is not sending value to its controller?

推荐答案

您需要指定 Html.BeginForm控制器和动作名称()如果不回发以生成该视图中的相同的方法

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

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

这篇关于里面的父视图不是将数据发送到控制器的局部视图 - asp.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆