0

データベースのデータを表示するドロップダウンリストがあります。ドロップダウンリストでデータベースデータを取得しますが、ドロップダウンリストで値を選択した後、コントローラーに渡したい選択した値を選択し、その選択した値のすべての詳細データを表示したいと思います。しかし、送信ボタンをクリックすると、ドロップダウンリストの選択された値がコントローラーに渡されません。

これは私のコードです

ビュー:Index.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Doctor_Request>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    SearchIndex
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>SearchIndex</h2>

    <%--<div id = "SelectDoctors">
          <% Html.RenderPartial("SelectDoctors"); %> 
    </div>--%>
    <script type="text/javascript">
        function TestFun() {
            var mdlno = $("#ddlMDLNo").val();
//            $.getJSON("/SearchMDLNo/getMDLNoDetails/" + mdlno, null, function (data) {

//                alert(data.Request_For_Id);
//            });
            var txtmdlno = document.getElementById("Request_For_Id");
            txtmdlno.value = mdlno;
            alert(txtmdlno.value);
        }
</script>

<div>
<h2>Search by MDLNo</h2>
     <% using (Html.BeginForm())
        { %>

         <%: Html.ValidationSummary(true, "Profile Updation was unsuccessful. Please correct the errors and try again.") %>

        Select MDLno 

        <%= Html.DropDownList("ddlMDLNo", ViewData["MDLno"] as SelectList, "--Select One--", new { onchange = "TestFun()" })%> 
        <%: Html.TextBoxFor(m => m.Request_For_Id)%>       

         <input type="submit" value="search" name="SearchMDLNo" />    
    <% } %>
</div>


<div> <% Html.RenderPartial("ListDoctors"); %></div>

</asp:Content>

コントローラー:SearchMDLNoController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ApricaCRMEvent.Models.CRM.DataLayer;
using ApricaCRMEvent.Models.CRM.DatabaseEntities;

namespace ApricaCRMEvent.Controllers
{
    public class SearchMDLNoController : Controller
    {
        CRM_Doctor_Request mdlnoObj = new CRM_Doctor_Request();

        public ActionResult Index()
        {
            ViewData["MDLno"] = new SelectList(SearchMDLNoDL.getAllMDLno(), "Request_For_Id", "Request_For_Id");
            return View();
        }

        [HttpPost]
        public ActionResult Index(CRM_Doctor_Request model)
        {
            ViewData["MDLno"] = new SelectList(SearchMDLNoDL.getAllMDLno(), "Request_For_Id", "Request_For_Id");

            //CRM_Doctor_Request mdlnoObj = SearchMDLNoDL.getMDLData("GJ04_D023");
            //mdlnoObj = SearchMDLNoDL.getMDLData(model.Request_For_Id);
            return View();
        }
        public ActionResult getMDLNoDetails(string id)
        {
            mdlnoObj=SearchMDLNoDL.getMDLData(id);
            return View();
        }
        public ActionResult ListDoctors()
        {
            return View(mdlnoObj);
        }

    }
}

これは部分的なビューであり、このビューで選択されたドロップダウン値..詳細データが表示されます

部分ビュー:ListDoctors.ascx

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Doctor_Request>" %>


<div><%: Html.DisplayFor(m => m.Request_For_Id) %></div>

<div>
<table>
    <tr>
        <th>
            Request_For_Id
        </th>
        <th>
            Territory
        </th>
        <th>
            Estimated_Amount
        </th>
        <th>
            Actual_Amount
        </th>
        <th>
            Date_Created
        </th>
        <th>
            Compute_CRM_State
        </th>
        <th>
            Compute_Event_Type
        </th>

    </tr>


    <tr>
        <td>
            <%: Html.DisplayFor(m => m.Request_For_Id) %>
        </td>
        <td>
            <%: Html.DisplayFor(m => m.Territory) %>
        </td>
        <td>
            <%: Html.DisplayFor(m => m.Estimated_Amount) %>
        </td>
        <td>
            <%: Html.DisplayFor(m => m.Actual_Amount) %>
        </td>
        <td>
            <%: Html.DisplayFor(m => m.Date_Created) %>
        </td>
        <td>
            <%: Html.DisplayFor(m => m.Compute_Service_State) %>
        </td>
        <td>
            <%: Html.DisplayFor(m => m.Compute_Event_Type) %>
        </td>
      </tr>


</table>

</div>

ドロップダウンリストで値を選択し、送信ボタンをクリックしても、値は渡されません。Index.aspxで、いくつかのjavascriptコードを試しましたが、機能しません。


コードを変更しました。そして今、これは機能しています。

ビュー:Index.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ApricaCRMEvent.Models.CRM.DatabaseEntities.CRM_Doctor_Request>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    SearchIndex
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>SearchIndex</h2>

    <%--<div id = "SelectDoctors">
          <% Html.RenderPartial("SelectDoctors"); %> 
    </div>--%>
    <script type="text/javascript">
        function TestFun() {
            var mdlno = $("#ddlMDLNo").val();

            var txtmdlno = document.getElementById("Request_For_Id");
            txtmdlno.value = mdlno;
            alert(txtmdlno.value);

        }
</script>

<div>
<h2>Search by MDLNo</h2>
     <% using (Html.BeginForm())
        { %>

         <%: Html.ValidationSummary(true, "Profile Updation was unsuccessful. Please correct the errors and try again.") %>

        Select MDLno 

        <%= Html.DropDownList("ddlMDLNo", ViewData["MDLno"] as SelectList, "--Select One--", new { onchange = "TestFun()" })%> 
        <%: Html.TextBoxFor(model => model.Request_For_Id) %>

         <input type="submit" value="search" name="SearchMDLNo" />    
    <% } %>
</div>


<%--<div> <% Html.RenderPartial("ListDoctors"); %></div>--%>
<div>
    <fieldset>
    <legend>CRM_Doctor_Request</legend>

    <div class="display-label">Territory</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Territory) %>
    </div>

    <div class="display-label">CRM_Request_For_Type_Id</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.CRM_Request_For_Type_Id) %>
    </div>

    <div class="display-label">Request_For_Id</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Request_For_Id) %>
    </div>

    <div class="display-label">Requestor</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Requestor) %>
    </div>

    <div class="display-label">Division_Id</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Division_Id) %>
    </div>

    <div class="display-label">Suggester</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Suggester) %>
    </div>

    <div class="display-label">Estimated_Amount</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Estimated_Amount) %>
    </div>

    <div class="display-label">Actual_Amount</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Actual_Amount) %>
    </div>

    <div class="display-label">Priority</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Priority) %>
    </div>

    <div class="display-label">CRM_Service_Type_Id</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.CRM_Service_Type_Id) %>
    </div>

    <div class="display-label">Deadline</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Deadline) %>
    </div>

    <div class="display-label">Executed_Date</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Executed_Date) %>
    </div>

    <div class="display-label">Entry_Done_By</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Entry_Done_By) %>
    </div>

    <div class="display-label">Date_Created</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Date_Created) %>
    </div>

    <div class="display-label">Date_Modified</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Date_Modified) %>
    </div>

    <div class="display-label">Event_Type_Id</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Event_Type_Id) %>
    </div>

    <div class="display-label">Compute_Event_Type</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Compute_Event_Type) %>
    </div>

    <div class="display-label">CRM_State_Id</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.CRM_State_Id) %>
    </div>

    <div class="display-label">Compute_CRM_State</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Compute_CRM_State) %>
    </div>

    <div class="display-label">Service_State_Id</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Service_State_Id) %>
    </div>

    <div class="display-label">Compute_Service_State</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Compute_Service_State) %>
    </div>

    <div class="display-label">Is_Active</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Is_Active) %>
    </div>

    <div class="display-label">Comment</div>
    <div class="display-field">
        <%: Html.DisplayFor(model => model.Comment) %>
    </div>
</fieldset>


</div>
</asp:Content>

コントローラー:SearchMDLNoController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ApricaCRMEvent.Models.CRM.DataLayer;
using ApricaCRMEvent.Models.CRM.DatabaseEntities;

namespace ApricaCRMEvent.Controllers
{
    public class SearchMDLNoController : Controller
    {
        CRM_Doctor_Request mdlnoObj = new CRM_Doctor_Request();

        public ActionResult Index()
        {
            ViewData["MDLno"] = new SelectList(SearchMDLNoDL.getAllMDLno(), "Request_For_Id", "Request_For_Id");
            return View();
        }

        [HttpPost]
        public ActionResult Index(CRM_Doctor_Request model)
        {
            ViewData["MDLno"] = new SelectList(SearchMDLNoDL.getAllMDLno(), "Request_For_Id", "Request_For_Id");

            //CRM_Doctor_Request mdlnoObj = SearchMDLNoDL.getMDLData("GJ04_D023");
            //mdlnoObj = SearchMDLNoDL.getMDLData(model.Request_For_Id);
            mdlnoObj = SearchMDLNoDL.getMDLData(model.Request_For_Id);
            return View(mdlnoObj);
        }
    }
}
4

1 に答える 1

0

これを試して :

$.getJSON("/SearchMDLNo/getMDLNoDetails",{id : mdlno}, function (data) {
         alert(data.Request_For_Id);
});

これはあなたのために働くはずです


<script type="text/javascript">
        function TestFun() {
            var mdlno = $("#ddlMDLNo").val();
            $.ajax({
              type: 'POST',
              dataType: 'json',
              data: {id: mdlno},
              success: function(result){
                      alert('success');
              }
            });
        }
</script>

次に、コントローラーで次のように変更します。

    [HttpPost]
    public ActionResult getMDLNoDetails(string id)
    {
        mdlnoObj=SearchMDLNoDL.getMDLData(id);
        return Json(true);
    }
于 2013-01-31T10:42:10.603 に答える