Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

A namespace cannot directly contain members such as fields, methods or statements

$
0
0

I started getting this error suddenly. Only this razor page throws the error!

A namespace cannot directly contain members such as fields, methods or statements

The last thing I did was publishing my blazor server to see if it works or not. I have tried clearing bin and obj folders but still getting the same error. I searched everywhere, an tried to reboot, close VS2022 and open it again but still the same.

@inject IOptionService OptionService@inject ModalService ModalServices    private string GenerateHtmlPreview()    {        bool hasEmptyData = false;        string html = @"<div class="""">";        int qId = 0, aId = 0;        foreach (var section in sections)        {            if (section.archived)                continue;            html += @"<div class=""mb-6"">";            if (!string.IsNullOrEmpty(section.title))                html += @"<div class=""mb-4 border-b border-gray-200 dark:border-gray-600 flex flex-wrap -mb-px text-sm font-medium text-center""><span class=""inline-block text-gray-900 text-lg dark:text-white border-blue-700 pb-1 border-b-2 rounded-t-lg"">" + section.title +"</span></div>";            else hasEmptyData = true;            foreach (var question in section.questions)            {                qId++;                if (question.archived)                    continue;                if (!string.IsNullOrEmpty(question.text))                {                    html += @"<div class=""mb-6""><label class=""form-label dark:text-white"">" + question.text +"</label>";                    switch (question.type)                    {                        case FieldType.SingleLineText:                            html += @$"<input placeholder=""{question.text}"" class=""form-input""></div>";                            break;                        case FieldType.ParagraphText:                            html += @$"<textarea placeholder=""{question.text}"" rows=""3"" class=""form-input""></textarea></div>";                            break;                        case FieldType.Date:                            html += @"<div class=""relative""><div class=""absolute inset-y-0 start-0 flex items-center ps-3""><svg class=""w-4 h-4 text-gray-500 dark:text-gray-400"" xmlns=""http://www.w3.org/2000/svg"" fill=""currentColor"" viewBox=""0 0 20 20""><path d=""M20 4a2 2 0 0 0-2-2h-2V1a1 1 0 0 0-2 0v1h-3V1a1 1 0 0 0-2 0v1H6V1a1 1 0 0 0-2 0v1H2a2 2 0 0 0-2 2v2h20V4ZM0 18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8H0v10Zm5-8h10a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z"" /></svg></div><input readonly type=""text"" placeholder=""Select date"" class=""font-bold cursor-pointer bg-gray-50 border w-full border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block ps-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500""></div>";                            break;                        case FieldType.MultipleChoices:                            foreach (var item in question.answers)                            {++aId;                                if (item.archived)                                    continue;                                if (!string.IsNullOrEmpty(item.text))                                {                                    html += $@"<div class=""flex items-center mb-4""><input id=""{aId}"" type=""radio"" name=""{qId}"" class=""w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600""><label for=""{aId}"" class=""ms-2 text-sm text-gray-900 dark:text-gray-300"">{item.text}</label></div>";                                }                            }                            html += "</div>";                            break;                        case FieldType.Checkboxes:                            foreach (var item in question.answers)                            {                                if (item.archived)                                    continue;                                if (!string.IsNullOrEmpty(item.text))                                {                                    html += $@"<div class=""flex items-center mb-4""><input type=""checkbox"" class=""w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600""><label class=""ms-2 text-sm text-gray-900 dark:text-gray-300"">{item.text}</label></div>";                                }                            }                            html += "</div>";                            break;                    }                }                else hasEmptyData = true;            }            html += "</div>";        }        if (hasEmptyData)            html = $@"<div class=""p-4 mb-4 text-sm rounded-lg text-yellow-800 bg-yellow-50 dark:bg-gray-800 dark:text-yellow-300"">Empty fields are not included in the preview.</div>" + html;        html += "</div>";        return html;    }

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>