Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used ViewComponent to display multiple photos in post edit view. But when the photos are loaded on the page, instead of going through that ViewComponent,again, it returns id with zero value and sends it to the controller and gives an error. where is the problem from?


What I have tried:

Post Edit View:

@model DataLayer.Models.ViewModels.Post.ShowPostListItemViewModel

@{
    ViewData["Title"] = "Post Edit";
}

<div class="row">
    <form method="post" asp-action="EditPost" enctype="multipart/form-data">
       <input type="hidden" asp-for="PostId" />
        <div class="col-lg-12 col-md-12 col-sm-12">
            <h1 class="page-header">Edit Post</h1>
        </div>
        <div class="row ">
            <div class="col-md-8 col-sm-8 col-lg-8">
                <div class="panel panel-primary">
                    
                    <div class="panel-body col-md-12 col-sm-12">
                       
                        <div class="form-group col-md-6 col-sm-6">
                            <label>Title</label>
                            <input type="text" asp-for="Title" class="form-control" />
                            
                        </div>
                       
                        <div class="form-group col-md-6 col-sm-6">
                            <label>Category</label>
                            <select type="text" asp-for="GroupId" asp-items="@(ViewData["Groups"] as SelectList)" class="form-control"></select>
                        </div>
                      
                        <br />
                        <br />
                        <br />

                        <div class="form-group col-md-12 col-sm-12">
                            <label>PostDescription</label>
                            <textarea  id ="Post_PostDescription" class="form-control" asp-for="Description" rows="10"></textarea>
                            
                        </div>
                    </div>
                   
                </div>
            </div>

            <div class="col-md-4 col-sm-4 col-lg-4">
                <div class="panel panel-default ">
                
                    <!-- /.panel-heading -->
                    <div class="panel-body col-md-12 col-sm-12 col-lg-12">
                     
                        @await Component.InvokeAsync("EditPostImageComponent",@Model.PostId)
                  
                      <div class="col-md-4">
                       <p></p>
                      
                            <div class="form-group">
                                <label>Select Image</label>
                                <input type="file" name="imgPostUp" id="imgPostUp"  multiple="multiple">
                            </div>
          
        
                        </div>
                     </div>
                  
                    <!-- /.panel-body -->
                </div>
            </div>

            <div class="col-md-12 col-sm-11">
                <p>
                    <input type="submit" value="Edit" class="btn btn-success" />
                    <a href="~/Admin/Post/GetPost" class="btn btn-danger ">Back</a>
                </p>
            </div>
        </div>
    </form>
</div>

@section Scripts
{
    <script>
        
        $("#imgPostUp").change(function () {
            readURL(this);
        });
    </script>
    
    <script src="https://cdn.ckeditor.com/4.9.2/standard/ckeditor.js"></script>
    <script>
    
        CKEDITOR.replace('Post_PostDescription', {
            customConfig: '/js/Config.js'
        });
   
    </script>
}
Posted
Updated 26-Sep-22 23:29pm
v2
Comments
Graeme_Grant 27-Sep-22 5:53am    
What is the exact error. Have you tried debugging. Have you set a breakpoint on the server to see what is being sent? Have you opened the dev tools to see the data being sent?

Please click on the GREEN "Improve Question" button and update your question with more information.
Member 13449171 27-Sep-22 8:33am    
Yes, I debugged, when the Edit view is opened and the photos are loaded, Id 0 is sent to the controller again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900