locked
Html.Partial מתרדנדר וחוזר כparent view RRS feed

  • שאלה

  • יש לי partial view שיש בו DDL שכאשר משנים בו ערך הוא צריך לרפרש נתונים של 2 דברים בתוך הpartial view 

    מה שעשיתי זה שבonchange הוא לוחץ על הform.submit ואכן הview מתרדנדר - הוא מגיע לaction המתאים בcontroller מקבל את תוכן הDDL

    ומחזיר בהתאמה את התוצאות המצופות - אבל במקום לחזור לparent view 

    הוא חוזר כ parent view - כלומר שורת הכתובת משתנה לכתובת של הpartial view..

    אין לי מושג איפה הטעות.. אשמח לעזרתכם!

    קוד...

    קריאה לpartial מתוך הparent view:

    @section SectorSection{
    
    <div id="sectorSection">
       
            @Html.Partial("_SectorSection", Model.SectorSection ) 
    </div>
    }

    ה partial view:

    @model MVCPrg.Views.ViewModels.SectorSectionViewModel
               
    @using (Ajax.BeginForm("SectorSection", null, new AjaxOptions()
                                                                {
                                                                    HttpMethod = "POST",
                                                                    UpdateTargetId = "sectorSection",
                                                                    InsertionMode = InsertionMode.Replace,
                                                                 }, new { id = "form_SectorSection" }))
    {
        
    <div style=" float:right; width:880px; font-family:Arial; color:#FFF; text-align: right;">
       
        <div style=" font-size:17px; padding-bottom:15px; padding-right:17px; width:800px; border-bottom:1px solid #fff; margin-bottom:20px;">בחר מגזר 
        @Html.DropDownListFor(s => s.SectorsSelected, Model.Sectors, new { @class = "ddlMainSector", onchange = "this.form.submit();" })</div>
        
    
        <div style="padding-right:17px; float: right; width:389px; font-size:20px; border-left:1px solid #fff; ">
            כמות נתונים למגזר<span style="font-size:30px;">@Model.CrrntAmount</span>
        </div>
    
        <div style="padding-right:20px;float: right; width:450px; font-size:20px;">
            ממוצע פניות  <span style="font-size:30px;">@Model.CrrntTurns</span> 
        </div>
    
        <button type="submit" style="display:none;" />
    </div>
    
        
        
    }
    

    הקונטרולר: 

            [HttpPost]
            public PartialViewResult SectorSection(SectorSectionViewModel SectorSection)
            {
                int sectorCode = SectorSection.SectorsSelected;
                if (sectorCode == 0) sectorCode = 11;
    
                IEnumerable<SelectListItem> Sectors = _secsService.GetSectors();
    
                double sectorAmount = _secsService.GetSectorAmount( sectorCode);
    
                int turns= _secsService.GetTurns( sectorCode);
    
    
                SectorSectionViewModel viewModel = new SectorSectionViewModel()
                {
                    Sectors = Sectors ,
                    SectorsSelected = sectorCode,
                    SectorAmount = sectorAmount ,
                    Turns= turns
                };
    
                return PartialView("_SectorSection",viewModel);
            }
    

    אם הreturn של הפונקציה הוא כמו שכתוב פה לעיל

    אני מגיע לדף חדש

    Home/SectorSection שבו מוצג רק הDDL.

    אם הreurn של הפונקציה הינו רק 

      return PartialView(viewModel);

    אז אני מקבלת הודעה שגיאה 404 למרות שהוא מגיע לאותו URL בדיוק כמו הקודם.

    אבל הבעיה היא למה הוא מגיע לURL הזה בכלל?? הוא היה אמור להישאר בדך Home/Index ורק לרענן את הpartial View??

    חוץ מכל מה שכתבתי לעיל מוגדר לי בweb.config:

       <add key="UnobtrusiveJavaScriptEnabled" value="true" />

    וגם בLayout.cshtml: 

     <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    
        <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    

    מה עוד יכול לגרום לבעיה??

    סליחה על האורך ( ניסיתי לענות מראש על שאלות שאולי תשאלו אותי..)

    בתודה!!!!!

    יום רביעי 30 מאי 2012 09:26

תשובות

  • יעזור מאוד אם תעלי דוגמת פרוייקט ל-SkyDrive או משהו בסגנון

    • סומן כתשובה על-ידי Eran Sharvit יום ראשון 03 יוני 2012 12:07
    שבת 02 יוני 2012 10:39
    מנחה דיון

כל התגובות

  • יעזור מאוד אם תעלי דוגמת פרוייקט ל-SkyDrive או משהו בסגנון

    • סומן כתשובה על-ידי Eran Sharvit יום ראשון 03 יוני 2012 12:07
    שבת 02 יוני 2012 10:39
    מנחה דיון
  • תודה אבל לא בטוח שאני יכולה לבודד רק את הדברים הבעייתים משאר הפרוייקט.. ובלי מודל כמובן..

    אם אתקע לחלוטין אז אולי אעשה את זה.. 

    יום ראשון 03 יוני 2012 06:18